Skip to content

Commit 76b7f5a

Browse files
authored
Added regression test
1 parent 8b03da0 commit 76b7f5a

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

tests/PHPStan/Rules/Variables/DefinedVariableRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,4 +1180,14 @@ public function testBug13353(): void
11801180
$this->analyse([__DIR__ . '/data/bug-13353.php'], []);
11811181
}
11821182

1183+
public function testBug13694(): void
1184+
{
1185+
$this->cliArgumentsVariablesRegistered = true;
1186+
$this->polluteScopeWithLoopInitialAssignments = true;
1187+
$this->checkMaybeUndefinedVariables = true;
1188+
$this->polluteScopeWithAlwaysIterableForeach = true;
1189+
1190+
$this->analyse([__DIR__ . '/data/bug-13694.php'], []);
1191+
}
1192+
11831193
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Bug13694;
4+
5+
/**
6+
* @param int[] $keys
7+
* @param array<int, int|null> $things
8+
*/
9+
function evaluateThings(array $keys, array $things): void
10+
{
11+
foreach ($keys as $key) {
12+
if (array_key_exists($key, $things) && $things[$key] === null) {
13+
echo "Value for key $key is null\n";
14+
continue;
15+
}
16+
17+
if (isset($things[$key])) {
18+
echo "Key $key is set\n";
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)