Skip to content

array_pop when array is list of string and size is known. #12675

Closed
phpstan/phpstan-src
#4036
@TheMarlboroMan

Description

@TheMarlboroMan

Bug report

Hi:

We got an assign.propertyType error in the following snippet

Assuming that explode returns a list of strings and since the size has already been asserted to be of two (or else we would throw), why would any call to array_shift or array_pop return null as long as the array has elements?

We tested this same code with direct array access ($pieces[0] and $pieces[1]) and everything is fine.

Code snippet that reproduces the problem

https://phpstan.org/r/f80ce8d4-5b2c-40f3-bd56-48ee5998a24f

Expected output

We would expect no issue to be detected. Please, correct us if we are wrong.

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

PHPStan makes me very, very, very happy on a daily basis. I feel much more confident in our codebase and it has helped us catch many obscure and insidious potential problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions