Bug #69051 [Opn->Nab]: Argument unpacking does not work in internal class constructor
| From: | nikic@php.net | Date: | Fri, 13 Feb 2015 13:48:54 +0000 |
| Subject: | Bug #69051 [Opn->Nab]: Argument unpacking does not work in internal class constructor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-190666@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
Updated by: nikic@php.net
Reported by: tom at r dot je
Summary: Argument unpacking does not work in internal class
constructor
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Arch Linux
PHP Version: 5.6.5
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2015-02-13 12:37:12] 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 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