Skip to content

Commit 555da34

Browse files
committed
Add test for unknown named parameters on native variadic functions
Adds a regression test for #14408 verifying that unknown named arguments passed to native variadic functions like sprintf() are properly detected.
1 parent 46b9819 commit 555da34

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,20 @@ public function testBugNumberFormatNamedArguments(): void
545545
$this->analyse([__DIR__ . '/data/number-format-named-arguments.php'], []);
546546
}
547547

548+
public function testBug14408(): void
549+
{
550+
if (PHP_VERSION_ID < 80000) {
551+
$this->markTestSkipped('Test requires PHP 8.0');
552+
}
553+
554+
$this->analyse([__DIR__ . '/data/bug-14408.php'], [
555+
[
556+
'Unknown parameter $foo in call to function sprintf.',
557+
6,
558+
],
559+
]);
560+
}
561+
548562
public function testArrayReduceCallback(): void
549563
{
550564
$this->analyse([__DIR__ . '/data/array_reduce.php'], [
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Bug14408;
4+
5+
// This should report an error: sprintf does not accept unknown named parameters
6+
sprintf(format: '%s', foo: 'bar');
7+
8+
// This should be fine: named parameter matches the signature
9+
sprintf(format: '%s %s', values: 'hello');
10+
11+
// call_user_func should accept unknown named args (forwards to callback)
12+
call_user_func('strtolower', str: 'HELLO');

0 commit comments

Comments
 (0)