Skip to content

Commit de955b5

Browse files
Add non regression test
1 parent e0c4844 commit de955b5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,4 +949,16 @@ public function testBug12447(): void
949949
]);
950950
}
951951

952+
public function testBug1061(): void
953+
{
954+
$this->reportPossiblyNonexistentConstantArrayOffset = true;
955+
956+
$this->analyse([__DIR__ . '/data/bug-1061.php'], [
957+
[
958+
"Offset 'one'|'two' might not exist on array{two: 1, three: 2}.",
959+
14,
960+
],
961+
]);
962+
}
963+
952964
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug1061;
4+
5+
class A {
6+
const KEYS = ["one", "two"];
7+
const ARR = [
8+
"two" => 1,
9+
"three" => 2
10+
];
11+
}
12+
13+
foreach (A::KEYS as $key) {
14+
echo A::ARR[$key];
15+
}

0 commit comments

Comments
 (0)