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

Explode returns false - false positive on < PHP 8 #4711

Closed
simPod opened this issue Mar 17, 2021 · 6 comments
Closed

Explode returns false - false positive on < PHP 8 #4711

simPod opened this issue Mar 17, 2021 · 6 comments

Comments

@simPod
Copy link
Contributor

simPod commented Mar 17, 2021

Bug report

explode() will return false if delimiter is empty string.

Making sure that the delimiter is not empty does not narrow the return type to array though.

https://phpstan.org/r/c1c8aa4a-cb73-4d9b-93bf-a28b1883cd8d

I would expect no errors on PHP 7.4.

@ondrejmirtes
Copy link
Member

There's currently no non-empty-string type in the typesystem, it's still an ordinary string after the condition: https://phpstan.org/r/e9ec2551-a6a0-4b24-ad3a-75c98fe4da6d

I plan to implement it, see #3981 for details.

@simPod
Copy link
Contributor Author

simPod commented Mar 17, 2021

I was looking for something similar to @psalm-trace. Thanks for \PHPStan\dumpType($string);!

@ondrejmirtes
Copy link
Member

Implemented by: phpstan/phpstan-src@6ef5e91

@tectiv3
Copy link

tectiv3 commented Jul 14, 2021

Sorry if I am hijacking this issue, but now on PHP 8 another false positive with explode and non-empty-string:
https://phpstan.org/r/742f9409-d0f3-497d-b022-53bb02e5134d

@ondrejmirtes
Copy link
Member

@tectiv3 Please create a separate issue, this one is unrelated.

@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 Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants