Bug #54944 [NEW]: Assignment operator assigns by reference on arrays containing objects.

From: Date: Fri, 27 May 2011 17:56:56 +0000
Subject: Bug #54944 [NEW]: Assignment operator assigns by reference on arrays containing objects.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161007@lists.php.net to get a copy of this message
From:             
Operating system: Mac OSX (Snow Leopard)
PHP version:      5.3.6
Package:          *General Issues
Bug Type:         Bug
Bug description:Assignment operator assigns by reference on arrays containing objects.

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 bug report at http://bugs.php.net/bug.php?id=54944&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=54944&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=54944&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=54944&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=54944&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54944&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=54944&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=54944&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=54944&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=54944&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=54944&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=54944&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=54944&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=54944&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=54944&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=54944&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=54944&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=54944&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=54944&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=54944&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=54944&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=54944&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#161007) next »