Skip to content

Commit 4782556

Browse files
committed
fix: dynamic variable error on isset
1 parent cb8cead commit 4782556

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/Rules/IssetCheck.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public function __construct(
4141
*/
4242
public function check(Expr $expr, Scope $scope, string $operatorDescription, string $identifier, callable $typeMessageCallback, ?IdentifierRuleError $error = null): ?IdentifierRuleError
4343
{
44+
// [FIX] Ignore isset($$foo): dynamic variable
45+
if (
46+
$expr instanceof Node\Expr\Variable &&
47+
$expr->name instanceof Node\Expr\Variable
48+
) {
49+
return null;
50+
}
51+
4452
// mirrored in PHPStan\Analyser\MutatingScope::issetCheck()
4553
if ($expr instanceof Node\Expr\Variable && is_string($expr->name)) {
4654
$hasVariable = $scope->hasVariableType($expr->name);

tests/PHPStan/Rules/Variables/IssetRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,4 +485,10 @@ public function testIssetAfterRememberedConstructor(): void
485485
]);
486486
}
487487

488+
public function testDynamicVariable(): void
489+
{
490+
$this->treatPhpDocTypesAsCertain = true;
491+
492+
$this->analyse([__DIR__ . '/data/dynamic-variable.php'], []);
493+
}
488494
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php declare(strict_types = 1);
2+
3+
$foo = 'bar';
4+
5+
if (!isset($$foo)) {
6+
echo 'Wololo';
7+
}

0 commit comments

Comments
 (0)