Skip to content

presence of __halt_compiler() and early exit() causes analysis to stop early #11179

@pilif

Description

@pilif

Bug report

In the attached snippet, function foo() is not analyzed (dumpType has no effect, but neither would any other code issue)

Observations:

  • If exit(0) is moved after the function, analysis completes correctly
  • if __halt_compiler() is removed, analysis completes correctly
  • In the snippet, an incorrect "Unreachable statement" is reported (caused by the exit)

What's scary is that the early exit() in this case causes everything between it and __halt_compiler() to not be checked at all.

Code snippet that reproduces the problem

https://phpstan.org/r/c7ad1609-8df3-4301-b13b-0b0921a449ec

Expected output

Dumped type: string

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

I'm still in the thick of tackling a 20+ years old codebase and I'm super happy with how well PHPStan works compared to the other project we used previously.

Compared other the other analyzer, I'm spending much less time adding @var workarounds because PHPStan is just so much better (and consistent!) at keeping up with the mess some of the very old parts of our code can be.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions