Thanks to visit codestin.com
Credit goes to github.com

Skip to content

array_shift()/array_pop() return type inference wrong depending on size of array #8030

@cs278

Description

@cs278

Bug report

Reproduced 1.8.3 and then on 1.8.5.

Edit: Also reproduced on 2.1.x.

When an array has a defined shape with count > 5 PHPStan seems to then believe that array_{shift,pop}() will always return a value from the array.

Code snippet that reproduces the problem

https://phpstan.org/r/090c443c-abb4-4bd4-a7cb-4bdc37f3d95d

Expected output

PHPStan shouldn't report any errors, like it does for the range a-d: https://phpstan.org/r/c77a36b5-49b7-498d-8499-67325939150b

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions