Skip to content

Always evaluated scope is not detected if condition is stronger #9685

Closed
phpstan/phpstan-src
#6380

Description

@mvorisek

Bug report

in the repro, there are two methods with the same code, in the 2nd method, an extra condition is added making the condition later stronger - but phpstan does handle it as weaker

Code snippet that reproduces the problem

https://phpstan.org/r/0715a034-ace4-4d2b-8099-05c6d34613ea

Expected output

no phpstan error

Activity

  1. added this to the Dependent types milestone on Aug 5, 2023
  2. mvorisek commented on Sep 2, 2023

    @mvorisek
    ContributorAuthor
  3. phpstan-bot commented on Sep 5, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    +PHP 8.4 (3 errors)
    +==========
    +
    +24: Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
    +39: Variable $scopeRestored might not be defined.
    +47: Variable $scopeRestored might not be defined.
    +
     PHP 8.0 – 8.3 (2 errors)
     ==========
     
    Full report

    PHP 8.4 (3 errors)

    Line Error
    24 Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.

    PHP 8.0 – 8.3 (2 errors)

    Line Error
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.

    PHP 7.2 – 7.4 (3 errors)

    Line Error
    4 Promoted properties are supported only on PHP 8.0 and later.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.
  4. phpstan-bot commented on Nov 1, 2025

    @phpstan-bot
    Contributor

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

    @@ @@
    +PHP 8.4 – 8.5 (3 errors)
    +==========
    +
    +24: Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
    +39: Variable $scopeRestored might not be defined.
    +47: Variable $scopeRestored might not be defined.
    +
     PHP 8.0 – 8.3 (2 errors)
     ==========
     
    Full report

    PHP 8.4 – 8.5 (3 errors)

    Line Error
    24 Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.

    PHP 8.0 – 8.3 (2 errors)

    Line Error
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.

    PHP 7.2 – 7.4 (3 errors)

    Line Error
    4 Promoted properties are supported only on PHP 8.0 and later.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.
  5. phpstan-bot commented on Sep 11, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    -PHP 8.0 – 8.3 (2 errors)
    +PHP 8.4 – 8.5 (4 errors)
     ==========
     
    +24: Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
     39: Variable $scopeRestored might not be defined.
     47: Variable $scopeRestored might not be defined.
    +48: Value assigned to variable $scopeRestored is never read.
     
    -PHP 7.2 – 7.4 (3 errors)
    +PHP 8.0 – 8.3 (3 errors)
     ==========
     
    +39: Variable $scopeRestored might not be defined.
    +47: Variable $scopeRestored might not be defined.
    +48: Value assigned to variable $scopeRestored is never read.
    +
    +PHP 7.2 – 7.4 (4 errors)
    +==========
    +
      4: Promoted properties are supported only on PHP 8.0 and later.
     39: Variable $scopeRestored might not be defined.
    -47: Variable $scopeRestored might not be defined.
    +47: Variable $scopeRestored might not be defined.
    +48: Value assigned to variable $scopeRestored is never read.
    Full report

    PHP 8.4 – 8.5 (4 errors)

    Line Error
    24 Deprecated in PHP 8.4: Parameter #1 $field (string) is implicitly nullable via default value null.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.
    48 Value assigned to variable $scopeRestored is never read.

    PHP 8.0 – 8.3 (3 errors)

    Line Error
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.
    48 Value assigned to variable $scopeRestored is never read.

    PHP 7.2 – 7.4 (4 errors)

    Line Error
    4 Promoted properties are supported only on PHP 8.0 and later.
    39 Variable $scopeRestored might not be defined.
    47 Variable $scopeRestored might not be defined.
    48 Value assigned to variable $scopeRestored is never read.
  6. 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.

  7. 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