Skip to content

False positive: Variable $a in isset() always exists and is not nullable. #2816

@klausi

Description

@klausi

Bug report

If you check a variable multiple times with isset() then PHPStan thinks the variable is always defined. But that is not the case. An isset() call does not define a variable.

Code snippet that reproduces the problem

<?php
if (isset($_GET['x'])) {
    $a = 1;
}

if (isset($a) === true) {
    echo "hello";
}

if (isset($a) === true) {
    echo "hello2";
}

https://phpstan.org/r/4fab31fc-425c-45c9-984c-8ab9358a7d4a

Actual output

+------------------------------------------------------------------+
| Line | test.php                                                  |
+------------------------------------------------------------------+
| 11   | Variable $a in isset() always exists and is not nullable. |
+------------------------------------------------------------------+

 [ERROR] Found 1 error 

Expected output

No output, because there is no problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions