Skip to content

Commit e5bbd49

Browse files
committed
Added regression test
1 parent 4f5f8f5 commit e5bbd49

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

tests/PHPStan/Rules/Arrays/DeadForeachRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ public function testBug2560(): void
5050
$this->analyse([__DIR__ . '/data/bug-2560.php'], []);
5151
}
5252

53+
public function testBug2457(): void
54+
{
55+
$this->analyse([__DIR__ . '/data/bug-2457.php'], []);
56+
}
57+
5358
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Bug2457;
4+
5+
class HelloWorld
6+
{
7+
public function sayHello(array $x, array $y): void
8+
{
9+
$a = [];
10+
$o = [];
11+
12+
foreach ($x as $t) {
13+
if (!isset($a[$t])) {
14+
$a[$t] = [];
15+
}
16+
$o[] = 'x';
17+
array_unshift($a[$t], count($o) - 1);
18+
}
19+
20+
foreach ($y as $t) {
21+
if (!isset($a[$t])) {
22+
continue;
23+
}
24+
foreach ($a[$t] as $b) {
25+
// this will be reached
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)