Req #17279 [Opn->Wfx]: array_recurse_safe()
| From: | maarten@php.net | Date: | Fri, 12 Jul 2013 13:20:41 +0000 |
| Subject: | Req #17279 [Opn->Wfx]: array_recurse_safe() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-180229@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=17279&edit=1
ID: 17279
Updated by: maarten@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