Phpinspectionsea: "Unnecessary parentheses" inspection on in-line type hinting results in invalid code

Created on 27 Feb 2018  路  3Comments  路  Source: kalessil/phpinspectionsea

The following code creates an "Unnecessary parentheses" notification:

if ((/** @var DateTime $test */ $test = $_SESSION['abc']) instanceof \DateTime) {
    echo 'do something';
}

Performing the auto-fix results in this invalid code:

if (/** @var DateTime $test */ instanceof \DateTime) {
    echo 'do something';
}

Executing the PHP script naturally results in an error:

Parse error: syntax error, unexpected 'instanceof' (T_INSTANCEOF) in C:\[....]\test.php on line 3
bug / false-positive fixed

Most helpful comment

Oops. Will fix it.

All 3 comments

Oops. Will fix it.

Fixed

Great job!

Was this page helpful?
0 / 5 - 0 ratings