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

From: Date: Fri, 13 Feb 2015 12:37:13 +0000
Subject: Bug #69051 [Opn]: Argument unpacking does not work in internal class constructor
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190661@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69051&edit=1 ID: 69051 User updated by: tom at r dot je Reported by: tom at r dot je Summary: Argument unpacking does not work in internal class constructor Status: Open Type: Bug Package: Scripting Engine problem Operating System: Arch Linux PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: Edit 2: I have found the source of the problem. The Phalcon PHP extension breaks this behaviour. I will report it to them, however an extension should not be able to break this behaviour. Previous Comments: ------------------------------------------------------------------------ [2015-02-13 12:34:18] tom at r dot je Edit: Strangely this does not seem consistent. This errors on my ArchLinux dev machine running PHP5.6.5 but does not cause an error on my CentOS server also running 5.6.5. ------------------------------------------------------------------------ [2015-02-13 12:18:08] tom at r dot je 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 this bug report at https://bugs.php.net/bug.php?id=69051&edit=1

« previous php.bugs (#190661) next »