Bug #75312 [Com]: inconsistent duck-typing with typed variadic arguments

From: Date: Thu, 05 Oct 2017 09:48:28 +0000
Subject: Bug #75312 [Com]: inconsistent duck-typing with typed variadic arguments
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211519@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75312&edit=1 ID: 75312 Comment by: spam2 at rhsoft dot net Reported by: michelv+php at gmail dot com Summary: inconsistent duck-typing with typed variadic arguments Status: Open Type: Bug Package: Scripting Engine problem Operating System: all PHP Version: 7.1.10 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2017-10-05 09:19:34] michelv+php at gmail dot com 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75312&edit=1

« previous php.bugs (#211519) next »