Skip to content

Says string is mixed after checked and exception thrown #9647

Closed

Description

@hopstad

Bug report

In the following example phpstan says that $string still can still be mixed even though the code will stop at the exception.

Code snippet that reproduces the problem

https://phpstan.org/r/064b8829-7e11-425f-b437-0a7e3c7c9df9

Expected output

No errors should be given

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

Helping me every day to make better code

Activity

  1. added this to the Easy fixes milestone on Jul 19, 2023
  2. ondrejmirtes commented on Jul 19, 2023

    @ondrejmirtes
    Member

    It's a bug, here's a workaround that works: https://phpstan.org/r/afd85807-fbc0-4874-b3cb-1d5b28ee20a4

  3. phpstan-bot commented on Sep 4, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    -19: Property test::$properString (string) does not accept mixed.
    +PHP 8.0 – 8.3 (1 error)
    +==========
    +
    +19: Property test::$properString (string) does not accept mixed.
    +
    +PHP 7.2 – 7.4 (6 errors)
    +==========
    +
    + 5: Property test::$properString is never written, only read.
    + 7: Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    + 7: Parameter $string of method test::doSomething() has invalid type mixed.
    +11: Call to function is_string() with mixed will always evaluate to false.
    +15: Variable $errors in empty() always exists and is not falsy.
    +19: Unreachable statement - code above always terminates.
    Full report

    PHP 8.0 – 8.3 (1 error)

    Line Error
    19 Property test::$properString (string) does not accept mixed.

    PHP 7.2 – 7.4 (6 errors)

    Line Error
    5 Property test::$properString is never written, only read.
    7 Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    7 Parameter $string of method test::doSomething() has invalid type mixed.
    11 Call to function is_string() with mixed will always evaluate to false.
    15 Variable $errors in empty() always exists and is not falsy.
    19 Unreachable statement - code above always terminates.
  4. phpstan-bot commented on Sep 4, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    -No errors
    +PHP 8.0 – 8.3
    +==========
    +
    +No errors
    +
    +PHP 7.2 – 7.4 (6 errors)
    +==========
    +
    + 5: Property test::$properString is never written, only read.
    + 7: Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    + 7: Parameter $string of method test::doSomething() has invalid type mixed.
    +11: Call to function is_string() with mixed will always evaluate to false.
    +15: Variable $errors in empty() always exists and is not falsy.
    +19: Unreachable statement - code above always terminates.
    Full report

    PHP 8.0 – 8.3

    No errors

    PHP 7.2 – 7.4 (6 errors)

    Line Error
    5 Property test::$properString is never written, only read.
    7 Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    7 Parameter $string of method test::doSomething() has invalid type mixed.
    11 Call to function is_string() with mixed will always evaluate to false.
    15 Variable $errors in empty() always exists and is not falsy.
    19 Unreachable statement - code above always terminates.
  5. phpstan-bot commented on Sep 24, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    -19: Property test::$properString (string) does not accept mixed.
    +PHP 8.0 – 8.3 (1 error)
    +==========
    +
    +19: Property test::$properString (string) does not accept mixed.
    +
    +PHP 7.2 – 7.4 (8 errors)
    +==========
    +
    + 5: Property test::$properString is never written, only read.
    + 7: Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    + 7: Parameter $string of method test::doSomething() has invalid type mixed.
    +11: Call to function is_string() with mixed will always evaluate to false.
    +11: Strict comparison using === between false and false will always evaluate to true.
    +15: Strict comparison using === between false and false will always evaluate to true.
    +15: Variable $errors in empty() always exists and is not falsy.
    +19: Unreachable statement - code above always terminates.
    Full report

    PHP 8.0 – 8.3 (1 error)

    Line Error
    19 Property test::$properString (string) does not accept mixed.

    PHP 7.2 – 7.4 (8 errors)

    Line Error
    5 Property test::$properString is never written, only read.
    7 Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    7 Parameter $string of method test::doSomething() has invalid type mixed.
    11 Call to function is_string() with mixed will always evaluate to false.
    11 Strict comparison using === between false and false will always evaluate to true.
    15 Strict comparison using === between false and false will always evaluate to true.
    15 Variable $errors in empty() always exists and is not falsy.
    19 Unreachable statement - code above always terminates.
  6. phpstan-bot commented on Sep 24, 2024

    @phpstan-bot
    Contributor

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

    @@ @@
    -No errors
    +PHP 8.0 – 8.3
    +==========
    +
    +No errors
    +
    +PHP 7.2 – 7.4 (7 errors)
    +==========
    +
    + 5: Property test::$properString is never written, only read.
    + 7: Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    + 7: Parameter $string of method test::doSomething() has invalid type mixed.
    +11: Call to function is_string() with mixed will always evaluate to false.
    +15: Strict comparison using === between false and false will always evaluate to true.
    +15: Variable $errors in empty() always exists and is not falsy.
    +19: Unreachable statement - code above always terminates.
    Full report

    PHP 8.0 – 8.3

    No errors

    PHP 7.2 – 7.4 (7 errors)

    Line Error
    5 Property test::$properString is never written, only read.
    7 Tip: Method test::doSomething() always throws an exception, it should have return type "never".
    7 Parameter $string of method test::doSomething() has invalid type mixed.
    11 Call to function is_string() with mixed will always evaluate to false.
    15 Strict comparison using === between false and false will always evaluate to true.
    15 Variable $errors in empty() always exists and is not falsy.
    19 Unreachable statement - code above always terminates.
  7. phpstan-bot commented on Feb 27, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5058

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

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