Bug #54944 [Opn->Bgs]: Assignment operator assigns by reference on arrays containing objects.

From: Date: Sat, 28 May 2011 16:21:24 +0000
Subject: Bug #54944 [Opn->Bgs]: Assignment operator assigns by reference on arrays containing objects.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161013@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54944&edit=1

 ID:                 54944
 Updated by:         johannes@php.net
 Reported by:        dtrenz at gmail dot com
 Summary:            Assignment operator assigns by reference on arrays
                     containing objects.
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            *General Issues
 Operating System:   Mac OSX (Snow Leopard)
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

Objects are reference types. For making an copy an explicit clone is
needed. PHP internal functions won't do that.


Previous Comments:
------------------------------------------------------------------------
[2011-05-27 19:56:56] dtrenz at gmail dot com

Description:
------------
When assigning one array to another array that contains a collection of
objects, 
the assignment is by reference.

Test script:
---------------
<?php
$obj = (object) null;
$obj->name = 'Joe';

$arrA = array($obj);
$arrB = array();

$arrB = $arrA;

$arrB[0]->name = 'Mary';

print_r($arrA);
print_r($arrB);

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

Array
(
    [0] => stdClass Object
        (
            [name] => Mary
        )
 
)

Actual result:
--------------
Array
(
    [0] => stdClass Object
        (
            [name] => Mary
        )
 
)

Array
(
    [0] => stdClass Object
        (
            [name] => Mary
        )
 
)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54944&edit=1


Thread (2 messages)

« previous php.bugs (#161013) next »