Skip to content

PHPStan reports that a variable is not defined in a case where it can simply determine that it is #13833

Closed
phpstan/phpstan-src
#6380

Description

@mind-bending-forks

Bug report

In https://phpstan.org/r/0a8e125c-c144-4f07-8e6f-676ae2679969, PHPStan is happy that $msg is 'hello' in the second if block, and reports no errors (except the dump type).

In https://phpstan.org/r/2b998eb6-acc1-422e-85c5-80ac7cd166c3, logically, $msg must still be 'hello' in the second if block. However, PHPStan gets confused and thinks it might be undefined (having type mixed), and so reports an error when the user attempts to use it.

Code snippet that reproduces the problem

https://phpstan.org/r/2b998eb6-acc1-422e-85c5-80ac7cd166c3

Expected output

PHPStan should determine that $msg has the value 'hello' in the second if block, and should not report any errors.

Hopefully, this a simple fix.

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

Yes.

Activity

  1. added this to the Dependent types milestone on Feb 9, 2026
  2. github-actions commented on Oct 13, 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.

  3. locked as resolved and limited conversation to collaborators on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions