|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2005-07-18 16:58 UTC] derick@php.net
  [2005-07-26 01:00 UTC] php-bugs at lists dot php dot net
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 11:00:01 2025 UTC | 
Description: ------------ My hosting company upgraded PHP 4.3 to 4.4 a week ago and an old function stopped working. It returns an object by reference -- but after the changes in 4.4 it doesn't work as expected. Reproduce code: --------------- class Foo { var $bar; } $_array = array(); function &new_foo() { global $_array; $_array[] = new Foo(); return ($_array[count($_array) - 1]); // return the object at end() } for ($i = 0; $i < 2; $i++) { $foo = &new_foo(); $foo->bar = 'foobar'.$i; } print_r($_array); Expected result: ---------------- In PHP 4.4, change the function to this: function &new_foo() { $object = new Foo(); $GLOBALS['_array'][] = &$object; return ($object); } The result will then be as in PHP 4.3: Array ( [0] => foo Object ( [bar] => foobar0 ) [1] => foo Object ( [bar] => foobar1 ) ) Actual result: -------------- Array ( [0] => foo Object ( [bar] => ) [1] => foo Object ( [bar] => ) )