Skip to content

Commit dae7c97

Browse files
Add non regression test
1 parent 6b2473a commit dae7c97

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
@@ -926,4 +926,16 @@ public function testBug3747(): void
926926
$this->analyse([__DIR__ . '/data/bug-3747.php'], []);
927927
}
928928

929+
public function testBug1061(): void
930+
{
931+
$this->reportPossiblyNonexistentConstantArrayOffset = true;
932+
933+
$this->analyse([__DIR__ . '/data/bug-1061.php'], [
934+
[
935+
"Offset 'one'|'two' might not exist on array{two: 1, three: 2}.",
936+
14,
937+
],
938+
]);
939+
}
940+
929941
}
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)