diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index e5d17aba80..caf980b796 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -990,6 +990,13 @@ public function testBug4532(): void ]); } + public function testBug12115(): void + { + $this->reportPossiblyNonexistentGeneralArrayOffset = true; + + $this->analyse([__DIR__ . '/data/bug-12115.php'], []); + } + public function testBug10492(): void { $this->analyse([__DIR__ . '/data/bug-10492.php'], [ @@ -1000,6 +1007,20 @@ public function testBug10492(): void ]); } + public function testBug12574a(): void + { + $this->reportPossiblyNonexistentGeneralArrayOffset = true; + + $this->analyse([__DIR__ . '/data/bug-12574a.php'], []); + } + + public function testBug12574b(): void + { + $this->reportPossiblyNonexistentGeneralArrayOffset = true; + + $this->analyse([__DIR__ . '/data/bug-12574b.php'], []); + } + public function testBug12926(): void { $this->reportPossiblyNonexistentGeneralArrayOffset = true; diff --git a/tests/PHPStan/Rules/Arrays/data/bug-12115.php b/tests/PHPStan/Rules/Arrays/data/bug-12115.php new file mode 100644 index 0000000000..043e7071f6 --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-12115.php @@ -0,0 +1,27 @@ + 0, 'string_index_2' => 0]; + } + + foreach ($loopArray as $loop) { + $stringIndex = $loop % 2 === 0 ? 'string_index_1' : 'string_index_2'; + $counterArray[$index][$stringIndex]++; + } + } + + } +} diff --git a/tests/PHPStan/Rules/Arrays/data/bug-12574a.php b/tests/PHPStan/Rules/Arrays/data/bug-12574a.php new file mode 100644 index 0000000000..591e49bd9a --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-12574a.php @@ -0,0 +1,15 @@ + 0) { + $r = rand(1, 10); + if (!isset($x[$r])) { + $x[$r] = 1; + } + var_dump($x[$r]); + } +} diff --git a/tests/PHPStan/Rules/Arrays/data/bug-12574b.php b/tests/PHPStan/Rules/Arrays/data/bug-12574b.php new file mode 100644 index 0000000000..d80a055762 --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-12574b.php @@ -0,0 +1,15 @@ +