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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
50 - 49 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Mar 28 12:01:27 2024 UTC