php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48380 Class is passed as reference in array?
Submitted: 2009-05-25 08:27 UTC Modified: 2009-05-25 08:32 UTC
From: catalint at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
 [2009-05-25 08:27 UTC] catalint at gmail dot com
Description:
------------
Class is passed as reference in array ?

Reproduce code:
---------------
$a= new stdClass();
$test=array();
for ($i=0;$i<5;$i++){
	$a->i=$i;
	$test[]=$a;
}
print_r($test);

Expected result:
----------------
Array
(
    [0] => stdClass Object
        (
            [i] => 0
        )

    [1] => stdClass Object
        (
            [i] => 1
        )

    [2] => stdClass Object
        (
            [i] => 2
        )

    [3] => stdClass Object
        (
            [i] => 3
        )

    [4] => stdClass Object
        (
            [i] => 4
        )

)

Actual result:
--------------
Array
(
    [0] => stdClass Object
        (
            [i] => 4
        )

    [1] => stdClass Object
        (
            [i] => 4
        )

    [2] => stdClass Object
        (
            [i] => 4
        )

    [3] => stdClass Object
        (
            [i] => 4
        )

    [4] => stdClass Object
        (
            [i] => 4
        )

)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-25 08:32 UTC] scottmac@php.net
Objects are always passed by reference.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 19:00:01 2025 UTC