Skip to content

False positive with array_pop on same line as array_unshift #13510

@hemberger

Description

@hemberger

Bug report

If I array_pop on a non-empty-array, the returned value is never null, and so I should be able to array_unshift that value back onto the array (i.e. array_unshift($arr, array_pop($arr))). However, if I perform this operation in a single line, there seems to be some issue with determining the type of the array after the array_pop. If I do the array_pop on a separate line, then the error goes away.

I should note that this only seems to occur inside a class (as per my reproducer). If I have a free function and pass the same array type to it, the same error is not emitted.

This error started showing up in PHPStan 2.1.23, so I'm guessing it may be related to phpstan/phpstan-src#4294.

Code snippet that reproduces the problem

https://phpstan.org/r/69eefbd3-ef7c-43f0-894a-d8be8912e202

Expected output

No error.

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

I haven't been able to do any PHP development for the past couple years, but I try to stay current with PHPStan versions. The work you all do is amazing, and I'm always fixing useful issues in my code as I update PHPStan!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions