php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28734 Operator = changes structure of self-referencing arrays
Submitted: 2004-06-10 20:46 UTC Modified: 2005-02-23 01:00 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: tomas_matousek at hotmail dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 5.0.0RC2 OS: WinXP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-06-10 20:46 UTC] tomas_matousek at hotmail dot com
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*
                        )

                )

        )
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-11 01:43 UTC] D dot Kingma at jool dot nl
Results on RC3:

Array
(
    [0] => 1
    [1] => Z
    [2] => 3
    [3] => 4
    [4] => Array
        (
            [0] => 1
            [1] => Z
            [2] => 3
            [3] => 4
            [4] => Array
 *RECURSION*
        )

)

Seems as aspected results
 [2004-06-11 09:38 UTC] tomas_matousek at hotmail dot com
Don't know how that is possible in your version of PHP 5.0.0 RC3, but in mine (I'm testing RC3 available on www.php.net not the latest version from CVS) the bug is still there (result is the same as I described in "Actual Result").
 [2004-06-11 19:40 UTC] imprestavel at gameguru dot com dot br
Tested PHP 5.0.0 RC3 and latest build (200406111430) under Windows2000 and had the same problem
 [2004-06-13 05:04 UTC] curt@php.net
Perhaps this can help track down the problem.
php 5.0.0RC3-dev:

[snip access array ouptut]
                   [4] => Array
                        (
                            [0] => 1
                            [1] => 2
                            [2] => 3
                            [3] => 4
                            [4] => Array
 *RECURSION*
                        )

                )

        )

)
/usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(662) :  Freeing 0x083C4208 (16 bytes), script=2873.php
/usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3413) :  Freeing 0x083C4150 (35 bytes), script=2873.php
/usr/home/curt/cvs/php/php-src/Zend/zend_hash.c(377) : Actual location (location was relayed)
Last leak repeated 3 times
/usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3382) :  Freeing 0x083C410C (16 bytes), script=2873.php
Last leak repeated 3 times
/usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3362) :  Freeing 0x083C4A6C (32 bytes), script=2873.php
/usr/home/curt/cvs/php/php-src/Zend/zend_hash.c(157) : Actual location (location was relayed)
Last leak repeated 1 time
=== Total 11 memory leaks detected ===

 [2005-02-15 01:42 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.0-win32-latest.zip

Can't reproduce with latest snapshots and releases under Linux.
 [2005-02-23 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 14:01:30 2024 UTC