ID:               33749
 Updated by:       [EMAIL PROTECTED]
 Reported By:      o dot persson at gmail dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         Variables related
 Operating System: Linux
 PHP Version:      4.4.0
 New Comment:

Try with error_reporting(E_ALL) at the start of your script...


Previous Comments:
------------------------------------------------------------------------

[2005-07-18 16:30:25] o dot persson at gmail dot com

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 this bug report at http://bugs.php.net/?id=33749&edit=1

Reply via email to