|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-03-01 00:08 UTC] skrol29forum at gmail dot com
Description:
------------
When $this is stored by reference in a PHP array, itself stored in a property, then function call_user_func_array() is able to recognize the reference only if called in the same local context where $this is referenced. In other words, the reference seems to be lost for call_user_func_array().
The bug does not occur with PHP 5.2,
It does occur with both PHP 5.3.0 and PHP 5.3.1. Not yet tested with PHP 5.3.2
Note that if we use a global variable instead of a property, then the bug does not occur.
Reproduce code:
---------------
<?php
function f_test(&$obj) {
$obj->prop++;
echo "prop=".$obj->prop." <br>\r\n";
}
class clsTest {
public $prop = 0;
public $arg_array = false;
function meth() {
if ($this->arg_array===false) $this->arg_array = array(&$this);
echo 'arg_array[0] '.(($this->arg_array[0]===$this) ? ' is the same instance' : ' is not the same instance').' than $this'." <br>\r\n";
call_user_func_array('f_test', $this->arg_array);
}
}
$oTest = new clsTest;
$oTest->meth(); // OK
$oTest->meth(); // ERR
?>
Expected result:
----------------
arg_array[0] is the same instance than $this
prop=1
arg_array[0] is the same instance than $this
Warning: Parameter 1 to f_test() expected to be a reference, value given in D:\www\bug.php on line 14
Actual result:
--------------
arg_array[0] is the same instance than $this
prop=1
arg_array[0] is the same instance than $this
prop=2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
I can reproduce it. array(1) { [0]=> &object(clsTest)#1 (2) { ["prop"]=> int(0) ["arg_array"]=> *RECURSION* } } prop=1 <br> array(1) { [0]=> object(clsTest)#1 (2) { ["prop"]=> int(1) ["arg_array"]=> *RECURSION* } } PHP Warning: Parameter 1 to f_test() expected to be a reference, value given