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 $argc, $argv global var type #1718
Conversation
global $argc, $argv; | ||
\PHPStan\Testing\assertType('mixed', $argc); // should be int<1, max> | ||
\PHPStan\Testing\assertType('mixed', $argv); // should be non-empty-array<int, string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried several things, but in the end wasn't able to identify this variable-scope.
therefore left it mixed
for now.. I don't think thats a very common thing anyway
(and we can't be 100% sure whether global $argc, $argv
actually references the builtin globals or a custom variable)
\PHPStan\Testing\assertType('int<1, max>', $argc); | ||
\PHPStan\Testing\assertType('non-empty-array<int, string>', $argv); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$argc/$argv always count/contain the program name you pass php test.php
, so actually you never have a empty type here.
actually this variable would only exist for a script run via the CLI SAPI, but I don't think we can differentiate CLI and WEB sapi.
FWIW, psalm also allows this 2 vars: https://psalm.dev/r/942a865551 and they are in the process of making them more precise in https://github.com/vimeo/psalm/pull/8473/files. I will look into making the super-globals more precise in a separate PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also test if these variables are locally created by the user and contain a different type.
\PHPStan\Testing\assertType('non-empty-array<int, string>', $argv); | ||
|
||
function f() { | ||
\PHPStan\Testing\assertType('*ERROR*', $argc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put this function in a use statement.
0a9465e
to
ba9d2f6
Compare
Thank you. |
refs vimeo/psalm#8473