Skip to content

False positive about overwritten throw/return when a finally conditionally exits #7665

Closed

Description

@Seldaek

Bug report

Somewhat related to #6119 but a different issue. Could be caused by #5627 I'm not sure.

Code snippet that reproduces the problem

https://phpstan.org/r/e19166e3-b9c5-4172-bbec-8fde5c73dc74

Expected output

No error as the throw is conditional and all the exits are conditional they should all be able to co-exist peacefully.

Activity

  1. phpstan-bot commented on Apr 3, 2024

    @phpstan-bot
    Contributor

    @Seldaek After the latest push in 1.11.x, PHPStan now reports different result with your code snippet:

    @@ @@
      7: Method HelloWorld::doStuff() should return string but return statement is missing.
      9: This throw is overwritten by a different one in the finally block below.
     13: This return is overwritten by a different one in the finally block below.
    +17: Expression "exit(1)" on a separate line does not do anything.
     17: This exit point is overwritten by a different one in the finally block below.
    +22: Expression "exit(1)" on a separate line does not do anything.
     22: The overwriting exit point is on this line.
    Full report
    Line Error
    7 Method HelloWorld::doStuff() should return string but return statement is missing.
    9 This throw is overwritten by a different one in the finally block below.
    13 This return is overwritten by a different one in the finally block below.
    17 Expression "exit(1)" on a separate line does not do anything.
    17 This exit point is overwritten by a different one in the finally block below.
    22 Expression "exit(1)" on a separate line does not do anything.
    22 The overwriting exit point is on this line.
  2. added a commit that references this issue on Mar 12, 2026
    225e1cd
  3. phpstan-bot commented on Mar 13, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5163

  4. github-actions commented on Apr 14, 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.

  5. locked as resolved and limited conversation to collaborators on Apr 14, 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

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions