Skip to content

Commit 9aeb490

Browse files
committed
Add regression test for #13694
1 parent b05cb5e commit 9aeb490

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,4 +1169,14 @@ public function testBug8719(): void
11691169
$this->analyse([__DIR__ . '/data/bug-8719.php'], []);
11701170
}
11711171

1172+
public function testBug13694(): void
1173+
{
1174+
$this->cliArgumentsVariablesRegistered = true;
1175+
$this->polluteScopeWithLoopInitialAssignments = true;
1176+
$this->checkMaybeUndefinedVariables = true;
1177+
$this->polluteScopeWithAlwaysIterableForeach = true;
1178+
1179+
$this->analyse([__DIR__ . '/data/bug-13694.php'], []);
1180+
}
1181+
11721182
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/**
4+
* @param int[] $keys
5+
* @param array<int, int|null> $things
6+
*/
7+
function evaluateThings(array $keys, array $things): void
8+
{
9+
foreach ($keys as $key) {
10+
if (array_key_exists($key, $things) && $things[$key] === null) {
11+
echo "Value for key $key is null\n";
12+
continue;
13+
}
14+
15+
if (isset($things[$key])) {
16+
echo "Key $key is set\n";
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)