Skip to content

Commit 08e38e2

Browse files
staabmondrejmirtes
authored andcommitted
Add regression test
1 parent deb0911 commit 08e38e2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -829,4 +829,11 @@ public function testArrayDimFetchAfterArraySearch(): void
829829
]);
830830
}
831831

832+
public function testBug8649(): void
833+
{
834+
$this->reportPossiblyNonexistentGeneralArrayOffset = true;
835+
836+
$this->analyse([__DIR__ . '/data/bug-8649.php'], []);
837+
}
838+
832839
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug8649;
4+
5+
class HelloWorld
6+
{
7+
public function test(): void
8+
{
9+
/** @var array{array{a: ?string}, array{b: ?string},} $test */
10+
$test = [
11+
['a' => 'test'],
12+
['b' => 'asdf'],
13+
];
14+
15+
foreach ($test as $property) {
16+
$firstKey = array_key_first($property);
17+
18+
if ($firstKey === 'b') {
19+
continue;
20+
}
21+
22+
echo($property[$firstKey]);
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)