php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45109 Inconsistent array loop
Submitted: 2008-05-27 18:47 UTC Modified: 2008-05-27 19:39 UTC
From: php-bug at undoso dot info Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.6 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php-bug at undoso dot info
New email:
PHP Version: OS:

 

 [2008-05-27 18:47 UTC] php-bug at undoso dot info
Description:
------------
When assigning into a cell of an array the array itself, the result is incoherent. Since the assignation does not use reference, the array should be copied and not create a magical structure that looks like an infinite loop.
The worst is that the array seems impossible to browse using PHP since there is no way to find that we are on a portion that we already visited, or not at my knowing.

Reproduce code:
---------------
$arr = array();
$arr["loop"] $ arr;
print_r($arr);


Expected result:
----------------
Array
(
    [loop] => Array
        (
        )

)

Here is what the resulting print_r should looks like. Since no reference is used, the array should be copied and only after that the loop cell created.

Actual result:
--------------
The constructed array looks like that:
Array
(
    [loop] => Array
 *RECURSION*
)
wich is inconsistent.

By the way, f you find a way to browse this array in PHP and detect that a recursion does exists, I want it because I just can't.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-05-27 18:54 UTC] php-bug at undoso dot info
Sorry, reproduce code is :
Reproduce code:
---------------
$arr = array();
$arr["loop"] = $arr;
print_r($arr);

and not the original one. I don't know how I did that change since I just copied the code from my test file...
 [2008-05-27 19:25 UTC] colder@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

Can't reproduce
 [2008-05-27 19:34 UTC] php-bug at undoso dot info
Yes, I was on 5.2.3. Looks like it is not doing that any more. Thanks a lot and sorry for the useless bug ^^
 [2008-05-27 19:35 UTC] php-bug at undoso dot info
Forgot to close the bug !
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC