php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69051 Argument unpacking does not work in internal class constructor
Submitted: 2015-02-13 12:18 UTC Modified: 2015-02-13 13:48 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: tom at r dot je Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.6.5 OS: Arch Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tom at r dot je
New email:
PHP Version: OS:

 

 [2015-02-13 12:18 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-02-13 12:34 UTC] 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:37 UTC] tom at r dot je
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.
 [2015-02-13 13:48 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2015-02-13 13:48 UTC] nikic@php.net
As you already found out, this is caused by a slightly incorrect execute_internal override in https://github.com/phalcon/cphalcon/blob/master/ext/phalcon.c#L50. See http://lxr.php.net/xref/PHP_5_6/Zend/zend_execute.c#1518 for how this should look like, in particular the first argument to the handler in the second branch.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 16:00:02 2026 UTC