From:             tomas_matousek at hotmail dot com
Operating system: WinXP
PHP version:      5.0.0RC2
PHP Bug Type:     Scripting Engine problem
Bug description:  Operator = changes structure of self-referencing arrays

Description:
------------
Create an array $b and set some of its item to reference the array itself
by =& operator. Then assign this array to some other variable. This
assignment (*) makes something wrong in the array $b because if you change
$b's items after this assignment the structure of array $b is changed.
However, if that assignment (*) doesn't take place the behavior is
correct.



Reproduce code:
---------------
$b = array(1,2,3,4);
$b[4] =& $b;

// this assignment probably makes changes to $b's structure
$c = $b;             

$b[1] = 'X';
$b[4][1] = 'Y';
$b[4][4][1] = 'Z';

print_r($b);


Expected result:
----------------
Array
(
    [0] => 1
    [1] => Z
    [2] => 3
    [3] => 4
    [4] => Array
 *RECURSION*
)

Actual result:
--------------
Array
(
    [0] => 1
    [1] => X
    [2] => 3
    [3] => 4
    [4] => Array
        (
            [0] => 1
            [1] => Y
            [2] => 3
            [3] => 4
            [4] => Array
                (
                    [0] => 1
                    [1] => Z
                    [2] => 3
                    [3] => 4
                    [4] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => Array
 *RECURSION*
                        )

                )

        )
)

-- 
Edit bug report at http://bugs.php.net/?id=28734&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=28734&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=28734&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=28734&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=28734&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=28734&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=28734&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=28734&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=28734&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=28734&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=28734&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=28734&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=28734&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28734&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=28734&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=28734&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=28734&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28734&r=float

Reply via email to