diff --git a/src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php b/src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php index 263a62aebf9..08e0794d0ca 100644 --- a/src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php +++ b/src/Rules/Arrays/NonexistentOffsetInArrayDimFetchCheck.php @@ -126,6 +126,9 @@ public function check( if ( $innerType->hasOffsetValueType($innerDimType)->no() ) { + if ($innerType->isString()->yes() && $innerDimType->isInteger()->yes()) { + continue; + } $report = true; break 2; } diff --git a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php index 7def992a257..d61948406c7 100644 --- a/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php +++ b/tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php @@ -1277,4 +1277,9 @@ public function testBug14308(): void $this->analyse([__DIR__ . '/data/bug-14308.php'], []); } + public function testBug13688(): void + { + $this->analyse([__DIR__ . '/data/bug-13688.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Arrays/data/bug-13688.php b/tests/PHPStan/Rules/Arrays/data/bug-13688.php new file mode 100644 index 00000000000..19a7d57a7af --- /dev/null +++ b/tests/PHPStan/Rules/Arrays/data/bug-13688.php @@ -0,0 +1,12 @@ + 0 && $input[$inputLen-1] === ':'; + echo $hasTrailingColon ? "{$input} has trailing colon\n" : "{$input} does not have trailing colon\n"; +}