|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-10-05 09:48 UTC] spam2 at rhsoft dot net
[2017-10-05 10:07 UTC] requinix@php.net
-Summary: inconsistent duck-typing with typed variadic
arguments
+Summary: Scalar typed variadic arguments accept other scalars
but not null
-Type: Bug
+Type: Documentation Problem
[2017-10-05 10:07 UTC] requinix@php.net
[2017-10-05 11:36 UTC] michelv+php at gmail dot com
[2022-04-22 13:21 UTC] ilutov@php.net
-Status: Open
+Status: Not a bug
[2022-04-22 13:21 UTC] ilutov@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
Description: ------------ 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. Test script: --------------- <?php function vsprintfProxy(string $format, string ...$args): string { return vsprintf($format, $args); } var_export(vsprintf('%s', [42])); var_export(vsprintfProxy('%s', 42)); echo "\n"; var_export(vsprintf('%s', [false])); var_export(vsprintfProxy('%s', false)); echo "\n"; var_export(vsprintf('%s', [null])); var_export(vsprintfProxy('%s', null)); echo "\n"; Expected result: ---------------- '42''42' '''' '''' Actual result: -------------- '42''42' '''' '' 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 Stack trace: #0 /in/pNqSi(17): vsprintfProxy('%s', NULL) #1 {main} thrown in /in/pNqSi on line 3 Process exited with code 255.