Skip to content

Commit 305e592

Browse files
committed
Regression test
Closes phpstan/phpstan#10492
1 parent 0e706b3 commit 305e592

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,4 +990,14 @@ public function testBug4532(): void
990990
]);
991991
}
992992

993+
public function testBug10492(): void
994+
{
995+
$this->analyse([__DIR__ . '/data/bug-10492.php'], [
996+
[
997+
'Offset 2|4 might not exist on array{array{0}, array{1}, array{2}}.',
998+
19,
999+
],
1000+
]);
1001+
}
1002+
9931003
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug10492;
4+
5+
/**
6+
* @return '02'|'04'
7+
*/
8+
function getIndex(int $input): string
9+
{
10+
if ($input > 5) {
11+
return '02';
12+
}
13+
14+
return '04';
15+
}
16+
17+
function (): void {
18+
$arr = [0 => [0], 1 => [1], 2 => [2]];
19+
echo print_r($arr[(int) getIndex(1)], true);
20+
};

0 commit comments

Comments
 (0)