From: skrol29forum at gmail dot com Operating system: Win7 PHP version: 5.3.1 PHP Bug Type: Class/Object related Bug description: error "expected to be a reference" when $this referenced in an array property
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 -- Edit bug report at http://bugs.php.net/?id=51174&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51174&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51174&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51174&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51174&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51174&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51174&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51174&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51174&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51174&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51174&r=support Expected behavior: http://bugs.php.net/fix.php?id=51174&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51174&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51174&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51174&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51174&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51174&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51174&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51174&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51174&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51174&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51174&r=mysqlcfg