go to bug id or search bugs for
Typed variadic arguments are now possible, but it looks like some duck-typing is still going on, because you can use integers or booleans for arguments like `string ...$args`. However you can not use null, that results in a fatal error.
If duck-typing should not happen at all, being able to use anything other than a string in that case is a bug.
If duck-typing is expected, then it's not working like it does in other parts of PHP, where null is accepted.
function vsprintfProxy(string $format, string ...$args): string
return vsprintf($format, $args);
Fatal error: Uncaught TypeError: Argument 2 passed to vsprintfProxy() must be of the type string, null given, called in /in/pNqSi on line 17 and defined in /in/pNqSi:3
#0 /in/pNqSi(17): vsprintfProxy('%s', NULL)
thrown in /in/pNqSi on line 3
Process exited with code 255.
Add a Patch
Add a Pull Request
in which other parts of PHP is NULL allowed in that case unless 7.1.x and explicit ?string instead only string
what you obviously want is strict typing, well than declare that in the first line of your files
This is loose typing, not duck typing.
Variadics typing follows the same rules as non-variadic typing:
> The declaration can be made to accept NULL values if the default value of the
> parameter is set to NULL.
> By default, PHP will coerce values of the wrong type into the expected scalar
> type if possible. For example, a function that is given an integer for a
> parameter that expects a string will get a variable of type string.
However the first part isn't possible for a variadic parameter so I think the "Variable-length argument lists" section should mention that NULLs aren't allowed.
At least not normally. The answer to that use case was the introduction of nullable types ("?string ...$args") but I can't find them documented anywhere besides the migration guide...
And as @spam2 said, it sounds like you want strict_types.
Related To: Bug #74024
My bad, I'm so used to having strict types declared that I forgot to declare them in 3v4l when I tested the functionality.
Thanks for the clarification!