Skip to content

Variable $ in empty() always exists and is not falsy. #14223

Closed

Description

@MacGritsch

Bug report

phpstan generates an error on the second usage of empty().
If it warns in this case, I think it should warn in both cases or none!?

It warns because one should use count($a)===0 or []===$a to check if the array $a is empty - instead of using the function empty(). But why does it warn only on second usage?

Code snippet that reproduces the problem

https://phpstan.org/r/fd296276-178b-48cc-b1b3-630a1917be27

Expected output

No issue or two issues, but not one.

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

ITS GREAT - THANK YOU!

Activity

  1. added this to the Easy fixes milestone on Mar 3, 2026
  2. added a commit that references this issue on Mar 3, 2026
    16e7765
  3. added a commit that references this issue on Mar 3, 2026
    f08de42
  4. phpstan-bot commented on Mar 3, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5124

  5. added 2 commits that reference this issue on Mar 3, 2026
    46df20f
    f08de42
  6. github-actions commented on Apr 4, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  7. locked as resolved and limited conversation to collaborators on Apr 4, 2026
  8. added a commit that references this issue on Apr 7, 2026
    42f716e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions