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

`count` after `explode` should make keys certain #3122

Open
BackEndTea opened this issue Mar 25, 2020 · 1 comment
Open

`count` after `explode` should make keys certain #3122

BackEndTea opened this issue Mar 25, 2020 · 1 comment

Comments

@BackEndTea
Copy link

@BackEndTea BackEndTea commented Mar 25, 2020

Bug report

explode will return a list of strings, so i'd expect that if i call count on that list the key information should be more clear to phpstan.

Code snippet that reproduces the problem

https://phpstan.org/r/2611be47-2295-4042-8a79-b6ff205162b9

Expected output

I'd expect there to be no issue for phpstan.

@ondrejmirtes
Copy link
Member

@ondrejmirtes ondrejmirtes commented Mar 25, 2020

The issue is rather that you'd want a general array (array<int, string>) after a count check specified to a concrete array shape with keys counted from zero. But PHPStan doesn't know that explode will return an array with keys counted from zero so right now it cannot make this specification.

I suggest this alternative for now: https://phpstan.org/r/f0c0dcf5-8001-461b-9f38-f3d189936fce

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.