Skip to content

Add test for unknown named parameters on native variadic functions#5433

Closed
Amoifr wants to merge 1 commit intophpstan:2.0.xfrom
Amoifr:fix/native-variadic-named-args
Closed

Add test for unknown named parameters on native variadic functions#5433
Amoifr wants to merge 1 commit intophpstan:2.0.xfrom
Amoifr:fix/native-variadic-named-args

Conversation

@Amoifr
Copy link
Copy Markdown

@Amoifr Amoifr commented Apr 8, 2026

This adds a regression test for phpstan/phpstan#14408.

The test verifies that unknown named arguments passed to native variadic functions like sprintf() are properly reported as errors, since PHP rejects them at runtime (ArgumentCountError: sprintf() does not accept unknown named parameters).

Based on code analysis, it appears the detection logic at FunctionCallParametersCheck:707 already handles this case (!$isNativelyVariadic || $isBuiltin), combined with the fact that Php8SignatureMapProvider strips the variadic parameter from namedArgumentsVariants. If the test passes on CI, this confirms the issue is already resolved in 2.0.x. If it fails, it pinpoints where the fix is needed.

Test cases:

  • sprintf(format: '%s', foo: 'bar') — should report Unknown parameter $foo
  • sprintf(format: '%s %s', values: 'hello') — should pass (known parameter)
  • call_user_func('strtolower', str: 'HELLO') — should pass (forwards args to callback)

Adds a regression test for #14408 verifying that unknown named arguments
passed to native variadic functions like sprintf() are properly detected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant