#31416 [NEW]: array_walk_recursive() strange behavior
| From: | sveta at microbecal dot com | Date: | Wed, 05 Jan 2005 12:51:59 +0000 |
| Subject: | #31416 [NEW]: array_walk_recursive() strange behavior | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-71480@lists.php.net to get a copy of this message | ||
From: sveta at microbecal dot com
Operating system: Win XP
PHP version: 5CVS-2005-01-05 (dev)
PHP Bug Type: Arrays related
Bug description: array_walk_recursive() strange behavior
Description:
------------
When I call
array_walk_recursive($array, array('Class', 'static_method1'), 'xxx');
and after it
array_walk_recursive($array, array('Class', 'static_method2'), 'xxx');
static_method2 was not called, but called static_method1
Is it right behavior?
Reproduce code:
---------------
class Test {
public static function rtrim(&$value, $key, $charlist = null) {
if (is_string($value)) {
if (null !== $charlist) {
$value = rtrim($value, $charlist);
} else {
$value = rtrim($value);
}
}
}
public static function add_suffix(&$value, $key, $suffix) {
$value = $value . $suffix;
}
}
$array = array('a' => array('b', 'c'),
'b' => array('d', 'e'),
);
array_walk_recursive($array, array('Test', 'add_suffix'), 'xxx');
var_dump($array);
array_walk_recursive($array, array('Test', 'rtrim'), 'xxx');
var_dump($array);
Expected result:
----------------
array(2) {
["a"]=>
array(2) {
[0]=>
string(4) "bxxx"
[1]=>
string(4) "cxxx"
}
["b"]=>
array(2) {
[0]=>
string(4) "dxxx"
[1]=>
string(4) "exxx"
}
}
array(2) {
["a"]=>
array(2) {
[0]=>
string(7) "b"
[1]=>
string(7) "c"
}
["b"]=>
array(2) {
[0]=>
string(7) "d"
[1]=>
string(7) "e"
}
}
Actual result:
--------------
array(2) {
["a"]=>
array(2) {
[0]=>
string(4) "bxxx"
[1]=>
string(4) "cxxx"
}
["b"]=>
array(2) {
[0]=>
string(4) "dxxx"
[1]=>
string(4) "exxx"
}
}
array(2) {
["a"]=>
array(2) {
[0]=>
string(7) "bxxxxxx"
[1]=>
string(7) "cxxxxxx"
}
["b"]=>
array(2) {
[0]=>
string(7) "dxxxxxx"
[1]=>
string(7) "exxxxxx"
}
}
--
Edit bug report at http://bugs.php.net/?id=31416&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31416&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31416&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31416&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31416&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31416&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31416&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31416&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31416&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31416&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31416&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31416&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31416&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31416&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31416&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31416&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31416&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31416&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31416&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31416&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31416&r=mysqlcfg