Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[FIX] dynamic variable undefined inside isset #4213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ga-devfront wants to merge 10 commits into phpstan:2.1.x
base: 2.1.x
Choose a base branch
Loading
from ga-devfront:fix/variable-undefined
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: dynamic variable error on isset
  • Loading branch information
ga-devfront committed Oct 20, 2025
commit 0fe2f51b3557c85a404dc8be82c3baccff054615
8 changes: 8 additions & 0 deletions src/Rules/IssetCheck.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ public function __construct(
*/
public function check(Expr $expr, Scope $scope, string $operatorDescription, string $identifier, callable $typeMessageCallback, ?IdentifierRuleError $error = null): ?IdentifierRuleError
{
// [FIX] Ignore isset($$foo): dynamic variable
if (
$expr instanceof Node\Expr\Variable &&
$expr->name instanceof Node\Expr\Variable
) {
return null;
}

// mirrored in PHPStan\Analyser\MutatingScope::issetCheck()
if ($expr instanceof Node\Expr\Variable && is_string($expr->name)) {
$hasVariable = $scope->hasVariableType($expr->name);
Expand Down
8 changes: 7 additions & 1 deletion tests/PHPStan/Rules/Variables/IssetRuleTest.php
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,13 @@ public function testIssetAfterRememberedConstructor(): void
]);
}

public function testDynamicVariable(): void
{
$this->treatPhpDocTypesAsCertain = true;

$this->analyse([__DIR__ . '/data/dynamic-variable.php'], []);
}

public function testPr4374(): void
{
$this->treatPhpDocTypesAsCertain = true;
Expand All @@ -510,5 +517,4 @@ public function testBug10640(): void

$this->analyse([__DIR__ . '/../../Analyser/nsrt/bug-10640.php'], []);
}

}
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Variables/data/dynamic-variable.php
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php declare(strict_types = 1);

$foo = 'bar';

if (!isset($$foo)) {
echo 'Wololo';
}

AltStyle によって変換されたページ (->オリジナル) /