php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33749 Return by reference issue
Submitted: 2005-07-18 16:30 UTC Modified: 2005-07-26 01:00 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: o dot persson at gmail dot com Assigned:
Status: No Feedback Package: Variables related
PHP Version: 4.4.0 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: o dot persson at gmail dot com
New email:
PHP Version: OS:

 

 [2005-07-18 16:30 UTC] 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] => 
        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-18 16:58 UTC] derick@php.net
Try with error_reporting(E_ALL) at the start of your script...
 [2005-07-26 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC