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
PHPStan falsely detects explode()
as returning empty arrays in cases where it doesn't
#3961
Comments
explode()
as returning empty arrays in cases where it doesn't
The thing is that PHPStan started to understand what non-empty-list is, nothing changed about explode() per se. We'd first have to have to implement support for non empty strings, which isn't too hard as I recently implemented support for numeric strings (phpstan/phpstan-src@1d27c61), then we would be able to know when we can be sure that explode() returns a non-empty array in its dynamic return type extension. As this is a very complex scenario, I consider this a feature request. |
This might be related to (or possibly a duplicate of) #3596. PHPStan didn't report the sample snippet as an error until the latest release which is why I thought it might be related to phpstan/phpstan-src@a4038b2 |
Just realized that |
Thanks for the quick fix! |
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. |
Bug report
The latest version of PHPStan incorrectly believes that the
explode()
function returns an empty array in cases where it doesn't.Per the PHP manual:
Code snippet that reproduces the problem
See https://phpstan.org/r/a664b522-b2d8-4541-a071-f1e768a0f9ad
This snippet will always return a non-empty array because (per the PHP documentation):
If delimiter is an empty string (""), explode() will return FALSE.The string is never going to be emptyIf delimiter contains a value that is not contained in string and a negative limit is used, then an empty array will be returnedwe're not providing a negative limit - we're using the default ofPHP_INT_MAX
Expected output
PHPStan should not report any false errors
The text was updated successfully, but these errors were encountered: