Skip to content
Browse files

Match PHP API; fix for PHP 5.4

  • Loading branch information...
1 parent 4224c5d commit 006032d2a2376bb4c82cb6f355d09c99b5490b3e @Tatsh committed May 17, 2012
Showing with 15 additions and 5 deletions.
  1. +6 −3 classes/sArray.php
  2. +9 −2 tests/sArrayTest.php
View
9 classes/sArray.php
@@ -292,13 +292,15 @@ private static function isArrayLike($value) {
* @param mixed $user_data User data to add as third argument to callback.
* @return void
*/
- private static function walkRecursiveCallback(sArray $instance, $array, $func, $user_data = NULL) {
+ private static function walkRecursiveCallback(sArray $instance, &$array, $func, $user_data = NULL) {
if (!self::isArrayLike($array)) {
return;
}
+
+ $func = fCore::callback($func);
foreach ($array as $key => $value) {
- fCore::call($func, array($key, $value, $user_data));
+ call_user_func_array($func, array(&$value, $key, $user_data));
if (self::isArrayLike($value)) {
self::walkRecursiveCallback($instance, $value, $func, $user_data);
}
@@ -316,8 +318,9 @@ private static function walkRecursiveCallback(sArray $instance, $array, $func, $
* @return sArray The object to allow method chaining.
*/
public function walkRecursive($func, $user_data = NULL) {
+ $func = fCore::callback($func);
foreach ($this->data as $key => $value) {
- fCore::call($func, array($key, $value, $user_data));
+ call_user_func_array($func, array(&$value, $key, $user_data));
self::walkRecursiveCallback($this, $value, $func, $user_data);
}
return $this;
View
11 tests/sArrayTest.php
@@ -160,7 +160,14 @@ public function testMerge() {
}
public static function walkCallback($a, $b, $user_data = NULL) {
- print $a.'=>'.$b.',';
+ if (is_array($a)) {
+ print join(',', $a);
+ }
+ else {
+ print $a;
+ }
+ print '=>';
+ print $b.',';
}
public function testWalk() {
@@ -180,7 +187,7 @@ public function testWalkModify() {
}
public function testWalkRecursive() {
- $this->expectOutputString('0=>1,1=>2,2=>3,3=>Array,0=>a,4=>a,1,0=>a,1=>Array,0=>1,5=>testSpecialContainer2,6=>testSpecialContainer3,');
+ $this->expectOutputString('1=>0,2=>1,3=>2,a=>3,a=>0,a,1=>4,a=>0,1=>1,1=>0,testSpecialContainer2=>5,testSpecialContainer3=>6,');
$a = new sArray(1,2,3, array('a'), new sArray('a', array(1)), new testSpecialContainer2, new testSpecialContainer3);
$this->assertEquals($a, $a->walkRecursive(self::walkCallback));
}

0 comments on commit 006032d

Please sign in to comment.
Something went wrong with that request. Please try again.