Req #53039 [NEW]: Extend array_walk_recursive to provide context information to the callback func

From: Date: Sun, 10 Oct 2010 21:21:17 +0000
Subject: Req #53039 [NEW]: Extend array_walk_recursive to provide context information to the callback func
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155066@lists.php.net to get a copy of this message
From:             
Operating system: Windows Server
PHP version:      5.3.3
Package:          Arrays related
Bug Type:         Feature/Change Request
Bug description:Extend array_walk_recursive to provide context information to the callback func

Description:
------------
It is easy to extend the array_walk_recursive function to be more useful in
non-
trivial situations which require information about depth & path in the
array 
structure the cursor is in, by adding an optional 4th parameter.  This
would 
eliminate the need for MANY user-written depth first search traversal
recursive 
functions.  Which consequently makes PHP a more attractive language for
people 
who 
fear recursion, but need a tree walk function which provides contextual 
information to the callback.

bool array_walk_recursive ( array &$input , callback $funcname [, mixed 
$userdata 
] [, array $state] )

where $state is a data dictionary having any number of context relevant
data 
e.g. 
the depth of recursion (int), and the keys traversed to arrive at this node
(a 
1-
dimensional list array of string).

This enhancement is low risk: it would not break backward-compatibility.
This enhancement is high reward: it would make Xpath-like operations more 
approachable to the average developer.
This enhancement would simplify user code: which tends to increase security
for 
websites.

Test script:
---------------
var $state = Array(
        $depth => 0
        ,$path => Array()
);

Expected result:
----------------
N/A

Actual result:
--------------
N/A

-- 
Edit bug report at http://bugs.php.net/bug.php?id=53039&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=53039&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=53039&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=53039&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=53039&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53039&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=53039&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=53039&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=53039&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=53039&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=53039&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=53039&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=53039&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=53039&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=53039&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53039&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53039&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=53039&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=53039&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=53039&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=53039&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=53039&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#155066) next »