diff --git a/src/Reflection/FunctionReflection.php b/src/Reflection/FunctionReflection.php index fabddd04fa..e7b12f316e 100644 --- a/src/Reflection/FunctionReflection.php +++ b/src/Reflection/FunctionReflection.php @@ -99,6 +99,16 @@ public function getParameters(): array true ); } + if ( + $this->reflection->getName() === 'unpack' + && PHP_VERSION_ID >= 70101 + ) { + $this->parameters[2] = new DummyParameter( + 'offset', + new IntegerType(false), + true + ); + } } return $this->parameters; diff --git a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php index 8902f444a6..19a30d1f78 100644 --- a/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php @@ -104,4 +104,34 @@ public function testCallToWeirdFunctions() ]); } + /** + * @requires PHP 7.1.1 + */ + public function testUnpackOnAfter711() + { + $this->analyse([__DIR__ . '/data/unpack.php'], [ + [ + 'Function unpack invoked with 0 parameters, 2-3 required.', + 3, + ], + ]); + } + + public function testUnpackOnBefore711() + { + if (PHP_VERSION_ID >= 70101) { + $this->markTestSkipped('This test requires PHP < 7.1.1'); + } + $this->analyse([__DIR__ . '/data/unpack.php'], [ + [ + 'Function unpack invoked with 0 parameters, 2 required.', + 3, + ], + [ + 'Function unpack invoked with 3 parameters, 2 required.', + 4, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/unpack.php b/tests/PHPStan/Rules/Functions/data/unpack.php new file mode 100644 index 0000000000..f5ac4f0e1b --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/unpack.php @@ -0,0 +1,4 @@ +