From:             
Operating system: Mac OSX
PHP version:      5.3.6
Package:          *General Issues
Bug Type:         Bug
Bug description:Array_merge links resulting array to source arrays by reference.

Description:
------------
When using array_merge() on an array of objects, the resulting array is
linked to 

the source array(s) as if passed by reference so that modifying the
resulting 

array after the merge ALSO modifies the source array.

Test script:
---------------
<?php



$obj = (object) null;

$obj->name = 'Bob';



$arrA = array();

$arrB = array($obj); // name = "Bob"



$arrA = array_merge($arrA, $arrB);



// Change name property of first element

$arrA[0]->name = 'Joe';



print_r($arrA);  // name = "Joe"

print_r($arrB);  // name = "Joe"; source array was modified, should still
be "Bob

Expected result:
----------------
Array

(

    [0] => stdClass Object

        (

            [name] => Joe

        )

 

)



Array

(

    [0] => stdClass Object

        (

            [name] => Bob

        )

 

)

Actual result:
--------------
Array

(

    [0] => stdClass Object

        (

            [name] => Joe

        )

 

)



Array

(

    [0] => stdClass Object

        (

            [name] => Joe

        )

 

)

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

Reply via email to