From d96aca923ed58f1d545f2cbc614860d2a817c640 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Jan 2026 10:11:24 +0100 Subject: [PATCH 1/4] Added regression test --- .../Variables/DefinedVariableRuleTest.php | 10 ++++++++++ .../Rules/Variables/data/bug-13694.php | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/PHPStan/Rules/Variables/data/bug-13694.php diff --git a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php index 76578a1e36..d45bfd61ae 100644 --- a/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php +++ b/tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php @@ -1180,4 +1180,14 @@ public function testBug13353(): void $this->analyse([__DIR__ . '/data/bug-13353.php'], []); } + public function testBug13694(): void + { + $this->cliArgumentsVariablesRegistered = true; + $this->polluteScopeWithLoopInitialAssignments = true; + $this->checkMaybeUndefinedVariables = true; + $this->polluteScopeWithAlwaysIterableForeach = true; + + $this->analyse([__DIR__ . '/data/bug-13694.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Variables/data/bug-13694.php b/tests/PHPStan/Rules/Variables/data/bug-13694.php new file mode 100644 index 0000000000..8d71a3a89c --- /dev/null +++ b/tests/PHPStan/Rules/Variables/data/bug-13694.php @@ -0,0 +1,19 @@ + $things + */ +function evaluateThings(array $keys, array $things): void +{ + foreach ($keys as $key) { + if (array_key_exists($key, $things) && $things[$key] === null) { + echo "Value for key $key is null\n"; + continue; + } + + if (isset($things[$key])) { + echo "Key $key is set\n"; + } + } +} From 97932abc11cf582cdd48b570a19aa77047a1177e Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Jan 2026 10:16:45 +0100 Subject: [PATCH 2/4] namespace --- tests/PHPStan/Rules/Variables/data/bug-13694.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/PHPStan/Rules/Variables/data/bug-13694.php b/tests/PHPStan/Rules/Variables/data/bug-13694.php index 8d71a3a89c..02638dc810 100644 --- a/tests/PHPStan/Rules/Variables/data/bug-13694.php +++ b/tests/PHPStan/Rules/Variables/data/bug-13694.php @@ -1,5 +1,7 @@ $things From 54c3ad69a2ec9e93e51ae28ba868c1c85a087a17 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Jan 2026 10:21:27 +0100 Subject: [PATCH 3/4] fix lint --- tests/PHPStan/Analyser/data/bug-13987.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PHPStan/Analyser/data/bug-13987.php b/tests/PHPStan/Analyser/data/bug-13987.php index a131a46a9b..5f5fb9612f 100644 --- a/tests/PHPStan/Analyser/data/bug-13987.php +++ b/tests/PHPStan/Analyser/data/bug-13987.php @@ -1,4 +1,4 @@ -= 8.1 namespace Bug13987; From df60ebcedb13c3a6f29a9542d2dff0531e77f7b0 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Wed, 21 Jan 2026 11:05:43 +0100 Subject: [PATCH 4/4] Update AnalyserIntegrationTest.php --- tests/PHPStan/Analyser/AnalyserIntegrationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index a5fedd94c7..413d8f160d 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1338,6 +1338,7 @@ public function testBug9994(): void $this->assertSame('Parameter #2 $callback of function array_filter expects (callable(1|2|3|null): bool)|null, false given.', $errors[1]->getMessage()); } + #[RequiresPhp('>= 8.1')] public function testBug13987(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-13987.php');