From: o dot persson at gmail dot com
Operating system: Linux
PHP version: 4.4.0
PHP Bug Type: Variables related
Bug description: Return by reference issue
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] =>
)
)
--
Edit bug report at http://bugs.php.net/?id=33749&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33749&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33749&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33749&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33749&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33749&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33749&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33749&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33749&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33749&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33749&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33749&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33749&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33749&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33749&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33749&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33749&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33749&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33749&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33749&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33749&r=mysqlcfg