Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more precise Superglobals / readonlySuperglobals #8037

Open
staabm opened this issue Sep 21, 2022 · 2 comments
Open

more precise Superglobals / readonlySuperglobals #8037

staabm opened this issue Sep 21, 2022 · 2 comments

Comments

@staabm
Copy link
Contributor

staabm commented Sep 21, 2022

Feature request

in psalm with vimeo/psalm#8473 recently more precise Superglobals were added.
I am thinking about doing the same for phpstan behind a readonlySuperglobals feature flag.

in tandem I would implement a new Rule which errors when code modifies one of the superglobal arrays.
(so we can "prevent" people writing types into a superglobal which don't fit the intended types)

https://phpstan.org/r/e99e22a3-014d-4edf-85ed-969857a34af5

wdyt?

@mvorisek
Copy link
Contributor

mvorisek commented Jun 7, 2023

Yes, for example $_GET can be only string or array of strings.

@phpstan-bot
Copy link
Contributor

@staabm After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

@@ @@
- 7: Dumped type: array<string, mixed>
- 8: Dumped type: array<string, mixed>
- 9: Dumped type: array<string, mixed>
-10: Dumped type: array<string, mixed>
-11: Dumped type: array<string, mixed>
-12: Dumped type: array<string, mixed>
-13: Dumped type: array<string, mixed>
-14: Dumped type: array<string, mixed>
+ 7: Dumped type: array
+ 8: Dumped type: array
+ 9: Dumped type: array
+10: Dumped type: array
+11: Dumped type: array
+12: Dumped type: array
+13: Dumped type: array
+14: Dumped type: array
Full report
Line Error
7 Dumped type: array
8 Dumped type: array
9 Dumped type: array
10 Dumped type: array
11 Dumped type: array
12 Dumped type: array
13 Dumped type: array
14 Dumped type: array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants