Skip to content

Execution branch confusion #5051

Closed
Closed

Description

@freiondrej

Bug report

Code snippet that reproduces the problem

https://phpstan.org/r/1978268f-c465-41c4-ad7f-970350cdd71e

Expected output

https://phpstan.org/r/3081cc1d-0af4-4df6-a9fe-dd23e2f23e14

I'd expect the two playgrounds to be functionally equivalent.

UPDATE: interestingly enough, this https://phpstan.org/r/ee4d6b0a-455e-4801-a2ee-828307eee5f1 works as expected... I thought maybe it's because $foo = 'bar'; / $foo = 'baz'; are not opposites, but that's not the case: https://phpstan.org/r/7e3409f7-e6a3-43e8-9c41-512d2145c021.

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

PHPStan is an invaluable tool in my development workflow. Thank you!

Activity

  1. added this to the Dependent types milestone on May 20, 2021
  2. ondrejmirtes commented on May 20, 2021

    @ondrejmirtes
    Member

    Hi, yeah, the "dependent types" feature can sometimes be flaky, it works in most basic scenarios only,personally I'd write this instead (that's solid): https://phpstan.org/r/b5f12e2e-9021-4936-9fcc-bcacb509efdd

    Thank you for the kind words!

  3. phpstan-bot commented on Oct 4, 2021

    @phpstan-bot
    Contributor

    @freiondrej After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

    @@ @@
    -16: Parameter #1 $object of function get_class expects object, object|null given.
    +No errors
  4. phpstan-bot commented on Oct 4, 2021

    @phpstan-bot
    Contributor

    @freiondrej After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

    @@ @@
    -16: Parameter #1 $object of function get_class expects object, object|null given.
    +No errors
  5. phpstan-bot commented on Feb 27, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5058

  6. github-actions commented on Mar 31, 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 Mar 31, 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

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions