-
Notifications
You must be signed in to change notification settings - Fork 541
ArrayDimFetch on class constant array can return null #3459
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
Conversation
we now see errors popping up in cases, where the implementation did not verify before whether the offset actually exists before fetching it (at least not in the method local code): phpstan-src/src/Type/Php/StrContainingTypeSpecifyingExtension.php Lines 61 to 70 in 06ab320
I am not sure this was done on purpose to prevent annoying PHPStan errors? |
just fixed the 2 extensions. as this change also fixes phpstan/phpstan#10847 I think its the right thing todo |
This pull request has been marked as ready for review. |
there is another ClassConstFetch bug for scalar constants: fix it here or in a new PR? |
There is a warning I feel like this PR doesn't go in the right direction since it basically enforce According to the doc with
is valid; but it won't with your PR, since it will report doFoo reports int|null. |
I think this PR is related but different. I am doing this logic on ClassConstFetch only, which means its about hardcoded constant arrays only. I think it won't affect your example - I will test in a few hours when in the train. |
I gave an example based on your example https://3v4l.org/us7UK and the PHPStan doc. But I can give another. https://phpstan.org/r/cf71d857-d4a7-4d98-ac07-4eabf80e1623
And I assume with your PR, it will report an error because it may returns |
less invasive fix in #3460 thanks for your feedback |
A offset array fetch on a constant array can return
null
if the offset does not exist, see https://3v4l.org/us7UKtriggered by #3453 (comment)
closes phpstan/phpstan#10847