Bug #69051 [NEW]: Argument unpacking does not work in internal class constructor

From: Date: Fri, 13 Feb 2015 12:18:08 +0000
Subject: Bug #69051 [NEW]: Argument unpacking does not work in internal class constructor
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190659@lists.php.net to get a copy of this message
From: tom at r dot je Operating system: Arch Linux PHP version: 5.6.5 Package: Scripting Engine problem Bug Type: Bug Bug description:Argument unpacking does not work in internal class constructor Description: ------------ Argument unpacking works in constructors for user-defined classes: class Foo { public function __construct($x) { echo $x; } } $f = ['Foo']; $foo = new Foo(...$f); Successfully prints "Foo" as the argument has been unpacked and passed into the constructor correctly. However, inexplicably, it does not work for internal classes: class Foo { public function __construct($x) { echo $x; } } $f = ['Foo']; $reflect = new ReflectionClass(...$f); Warning: ReflectionClass::__construct() expects exactly 1 parameter, 0 given in $file on line $line In other cases it creates an exception: $f = ['Foo']; $dir = new DirectoryIterator(...$f); Fatal error: Uncaught exception 'UnexpectedValueException' with message 'DirectoryIterator::__construct() expects exactly 1 parameter, 0 given' in $file Test script: --------------- class Foo { public function __construct($x) { echo $x; } } $f = ['Foo']; $foo = new Foo(...$f); $reflect = new ReflectionClass(...$f); $dir = new DirectoryIterator(...$f); Expected result: ---------------- Internal classes get constructed successfully Actual result: -------------- Internal classes either throw a warning or an exception -- Edit bug report at https://bugs.php.net/bug.php?id=69051&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69051&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69051&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69051&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69051&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69051&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69051&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69051&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69051&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69051&r=support Expected behavior: https://bugs.php.net/fix.php?id=69051&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69051&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69051&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69051&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69051&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69051&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69051&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69051&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69051&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69051&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69051&r=mysqlcfg

« previous php.bugs (#190659) next »