Skip to content

Incorrect analyzing of array_shift with non-empty-list #13438

@ryazanov13

Description

@ryazanov13

Bug report

array_shift can return null if the array is empty, and also make it empty if there was a last element. phpstan allows using array_shift even when there is a last element left in the array for the non-empty-list field type.

As a result, we have an empty list in the non-empty-list field, and we expect that array_shift will never return null.

Code snippet that reproduces the problem

https://phpstan.org/r/e92d9e9d-0f01-42d5-b04f-337ca8c64157

Expected output

error in test2
the reason is to make sure that there is more than one element in the array

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions