Edit report at https://bugs.php.net/bug.php?id=17279&edit=1

 ID:                 17279
 Updated by:         maar...@php.net
 Reported by:        tomat at lenderlabdot dot com
 Summary:            array_recurse_safe()
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
-Package:            Feature/Change Request
+Package:            *General Issues
 Operating System:   All
 PHP Version:        4.1.2
 Block user comment: N
 Private report:     N

 New Comment:

Related issue already fixed this problem.


Previous Comments:
------------------------------------------------------------------------
[2002-05-16 18:09:50] tomat at lenderlabdot dot com

Will solve problems like:

http://bugs.php.net/bug.php?id=16064

This code doesn't work, but I don't know enough C to write it right.  It would 
work if PHP had a method for determining if two variables are the same 
reference. (unless there is one that I haven't found...)

<?php
$a=array(1,2,3);
$a[3]=&$a;
$a=array_recurse_safe($a);
array_merge_recursive($a,$a);
var_dump($a);

function array_recurse_safe($array, $parents=array()) {
    $parents[]=&$array;
    foreach($array as $element) {
        if(is_array($element) || is_object($element)) {
            $loop=false;
            foreach($parents as $parent) {
                if(&$parent == &$element) {
                    unset($element);
                    $loop=true;
                }
            }
            if(!$loop) {
                $element=array_recurse_safe($element, $parents);
            }
        }
    }
    return $array;
}
?>

Also, the usage of unset() is improper here, but I left it in for simplicity.

------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=17279&edit=1

Reply via email to