From 58d9e00f1e8b583542257660edb976d2dbd71f63 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 28 Sep 2025 13:06:28 +0200 Subject: [PATCH 1/5] Added regression test --- ...nexistentOffsetInArrayDimFetchRuleTest.php | 7 +++++ tests/PHPStan/Rules/Arrays/data/bug-12115.php | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-12115.php diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index e5d17aba80..ea2f51a71e 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'], [ 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]++; + } + } + + } +} From 99957e05963948e6747a93c8123c799c2903490b Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 28 Sep 2025 13:16:19 +0200 Subject: [PATCH 2/5] another test --- .../NonexistentOffsetInArrayDimFetchRuleTest.php | 5 +++++ tests/PHPStan/Rules/Arrays/data/bug-12574a.php | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-12574a.php diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index ea2f51a71e..a57fb1bd03 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -1007,6 +1007,11 @@ public function testBug10492(): void ]); } + public function testBug12574a(): void + { + $this->analyse([__DIR__ . '/data/bug-12574a.php'], []); + } + public function testBug12926(): void { $this->reportPossiblyNonexistentGeneralArrayOffset = true; 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]); + } +} From 60c0cd959d0948084e89260518729b79073574e9 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 28 Sep 2025 13:18:29 +0200 Subject: [PATCH 3/5] Update NonexistentOffsetInArrayDimFetchRuleTest.php --- .../Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index a57fb1bd03..49a98f8691 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -1009,6 +1009,8 @@ public function testBug10492(): void public function testBug12574a(): void { + $this->reportPossiblyNonexistentGeneralArrayOffset = true; + $this->analyse([__DIR__ . '/data/bug-12574a.php'], []); } From 998dcd3a5da1ee74aa80435fc0ba102c07d5b57f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 28 Sep 2025 13:20:04 +0200 Subject: [PATCH 4/5] Update NonexistentOffsetInArrayDimFetchRuleTest.php --- .../Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 49a98f8691..caf980b796 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -1014,6 +1014,13 @@ public function testBug12574a(): void $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; From 557415943c2bd2589c9d15b23c8996fca652fe62 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 28 Sep 2025 13:20:07 +0200 Subject: [PATCH 5/5] Create bug-12574b.php --- tests/PHPStan/Rules/Arrays/data/bug-12574b.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/PHPStan/Rules/Arrays/data/bug-12574b.php 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 @@ +