Skip to content

Commit

Permalink
Add regression test for 5805
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm committed Nov 19, 2022
1 parent 8358f29 commit 8a18dea
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php
Expand Up @@ -918,4 +918,13 @@ public function testBug4173(): void
]);
}

public function testBug5805(): void
{
$this->cliArgumentsVariablesRegistered = true;
$this->polluteScopeWithLoopInitialAssignments = false;
$this->checkMaybeUndefinedVariables = true;
$this->polluteScopeWithAlwaysIterableForeach = true;
$this->analyse([__DIR__ . '/data/bug-5805.php'], []);
}

}
17 changes: 17 additions & 0 deletions tests/PHPStan/Rules/Variables/data/bug-5805.php
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace Bug5805;

(function (): void {
if (!($_GET['foo'])) { // if 'foo' is falsy, SET $var
$var = "set";
}

if ($_GET['foo']) {

} else {
// Foo is falsy, var should have been set.

echo $var;
}
})();

0 comments on commit 8a18dea

Please sign in to comment.