|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-11-17 15:24 UTC] sjon at hortensius dot net
Description: ------------ The changelog states: > Improved performance of array_merge() and func_get_args() by eliminating useless copying. I think I found a bug related to this change. If it's not fixed it should at least be documented. Test script: --------------- From http://3v4l.org/U40T0 <?php class f { function f(&$e){} } function getNew() { $a = func_get_args(); $c = array_shift($a); $r = new ReflectionClass($c); return $r->newInstanceArgs($a); } $e = new stdClass; var_dump(getNew('f', $e)); Expected result: ---------------- object(f)#3 (0) { } Actual result: -------------- Warning: Parameter 1 to f::f() expected to be a reference, value given in /in//in/U40T0 on line 14 Warning: ReflectionClass::newInstanceArgs(): Invocation of f's constructor failed in /in//in/U40T0 on line 14 NULL PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 12:00:01 2025 UTC |
Actually, this code worked not on purpose but because of luck. Previously, func_get_args() copied each argument making refcount == 1 and it allowed to pass it by reference. The following code demonstrates the real reason of the bug. The first call to call_user_func_array() works but the second doesn't. <?php function foo(&$e) { var_dump($e); } call_user_func_array("foo", array(2)); $a = array(2); call_user_func_array("foo", $a); ?> The problem may be related to zend_fcall_info.no_separation handling.