|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-02-13 12:34 UTC] tom at r dot je
[2015-02-13 12:37 UTC] tom at r dot je
[2015-02-13 13:48 UTC] nikic@php.net
-Status: Open
+Status: Not a bug
[2015-02-13 13:48 UTC] nikic@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 16:00:02 2026 UTC |
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