diff --git a/src/Type/Constant/ConstantArrayType.php b/src/Type/Constant/ConstantArrayType.php index ba30e4f5fe..ac91966025 100644 --- a/src/Type/Constant/ConstantArrayType.php +++ b/src/Type/Constant/ConstantArrayType.php @@ -1019,6 +1019,9 @@ public function sliceArray(Type $offsetType, Type $lengthType, TrinaryLogic $pre public function spliceArray(Type $offsetType, Type $lengthType, Type $replacementType): Type { $keyTypesCount = count($this->keyTypes); + if ($keyTypesCount === 0) { + return $this; + } $offset = $offsetType instanceof ConstantIntegerType ? $offsetType->getValue() : null; diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 0a80bdf1c7..898add9bcf 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -1493,6 +1493,13 @@ public function testBug12095(): void $this->assertNoErrors($errors); } + public function testBug13279(): void + { + $errors = $this->runAnalyse(__DIR__ . '/data/bug-13279.php'); + $this->assertCount(1, $errors); + $this->assertSame('Parameter #2 $offset of function array_splice expects int, string given.', $errors[0]->getMessage()); + } + /** * @param string[]|null $allAnalysedFiles * @return Error[] diff --git a/tests/PHPStan/Analyser/data/bug-13279.php b/tests/PHPStan/Analyser/data/bug-13279.php new file mode 100644 index 0000000000..feb687a3ed --- /dev/null +++ b/tests/PHPStan/Analyser/data/bug-13279.php @@ -0,0 +1,18 @@ +