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

Incorrect array_search() type under certain conditions #7809

Closed
zeriyoshi opened this issue Aug 18, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1633
Closed

Incorrect array_search() type under certain conditions #7809

zeriyoshi opened this issue Aug 18, 2022 · 3 comments · Fixed by phpstan/phpstan-src#1633

Comments

@zeriyoshi
Copy link

Bug report

Passing the $strict argument of array_search() from a function reports the possibility of null being returned.

Code snippet that reproduces the problem

https://phpstan.org/r/063ed345-07db-45c1-8b05-0fee820294cd

Expected output

array_search() will never return null in any case.

Did PHPStan help you today? Did it make you happy in any way?

Thanks to PHPStan, various bugs have been prevented. Awesome!

@herndlm
Copy link
Contributor

herndlm commented Aug 18, 2022

the return type extension for array_search looks quite complicated, I think it can be refactored and cleaned up bit. irregardless, it looks like null is returned in pre PHP 8 if the second argument is not an array for example https://3v4l.org/8nMtV. but there are a couple of old tests for that already.

it should no be returned in your case though, I agree.

@zeriyoshi
Copy link
Author

I was not aware of the possibility of null being returned in PHP 7.4. Thanks. You might want to handle this based on the value of the phpVersion configuration. (but may be unnecessary since it should be detected as an illegal argument in the first place)

https://phpstan.org/config-reference#phpversion

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants