Bug #75312 [NEW]: inconsistent duck-typing with typed variadic arguments
| From: | michelv+php at gmail dot com | Date: | Thu, 05 Oct 2017 09:19:38 +0000 |
| Subject: | Bug #75312 [NEW]: inconsistent duck-typing with typed variadic arguments | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-211518@lists.php.net to get a copy of this message | ||
From: michelv+php at gmail dot com
Operating system: all
PHP version: 7.1.10
Package: Scripting Engine problem
Bug Type: Bug
Bug description:inconsistent duck-typing with typed variadic arguments
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 bug report at https://bugs.php.net/bug.php?id=75312&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75312&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75312&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75312&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75312&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75312&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75312&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75312&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75312&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75312&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75312&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75312&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75312&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75312&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75312&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75312&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75312&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75312&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75312&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75312&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75312&r=mysqlcfg