Skip to content

Variable in empty() always exists and is not falsy together with array_shift #12658

@renatonascalves

Description

@renatonascalves

Feature request

I run into a piece of code that I'd swear PHPStan would be able to understand it but it doesn't. I wonder if that's on purpose or maybe I'm misunderstanding something.

Here is the snippet: https://phpstan.org/r/870e4f7c-d387-4506-9117-bf99e41eb570
And the PHP code to compare the output: https://3v4l.org/1Icqf#v8.3.17

In a nutshell, in a foreach loop, with array_shift, PHPStan is considering the array as non-empty because of the default value set before the foreach but it is not smart enough to see it could be empty since the array_shift could strip all values inside the loop.

So the ! empty( $ads ) conditional is a valid in this instance.

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

Yes! Every single day! <3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions