1--TEST-- 2Test array_walk_recursive() function : object functionality - array of objects 3--FILE-- 4<?php 5/* 6* Testing array_walk_recursive() with an array of objects 7*/ 8 9echo "*** Testing array_walk_recursive() : array of objects ***\n"; 10 11function callback_private($value, $key, $addValue) 12{ 13 echo "value : "; 14 var_dump($value->getValue()); 15 echo "key : "; 16 var_dump($key); 17} 18 19function callback_public($value, $key) 20{ 21 echo "value : "; 22 var_dump($value->pub_value); 23} 24function callback_protected($value, $key) 25{ 26 echo "value : "; 27 var_dump($value->get_pro_value()); 28} 29 30class MyClass 31{ 32 private $pri_value; 33 public $pub_value; 34 protected $pro_value; 35 public function __construct($setVal) 36 { 37 $this->pri_value = $setVal; 38 $this->pub_value = $setVal; 39 $this->pro_value = $setVal; 40 } 41 public function getValue() 42 { 43 return $this->pri_value; 44 } 45 public function get_pro_value() 46 { 47 return $this->pro_value; 48 } 49}; 50 51// array containing objects of MyClass 52$input = array ( 53 array( 54 new MyClass(3), 55 new MyClass(10), 56 ), 57 new MyClass(20), 58 array(new MyClass(-10)) 59); 60 61echo "-- For private member --\n"; 62var_dump( array_walk_recursive($input, "callback_private", 1)); 63echo "-- For public member --\n"; 64var_dump( array_walk_recursive($input, "callback_public")); 65echo "-- For protected member --\n"; 66var_dump( array_walk_recursive($input, "callback_protected")); 67 68echo "Done" 69?> 70--EXPECT-- 71*** Testing array_walk_recursive() : array of objects *** 72-- For private member -- 73value : int(3) 74key : int(0) 75value : int(10) 76key : int(1) 77value : int(20) 78key : int(1) 79value : int(-10) 80key : int(0) 81bool(true) 82-- For public member -- 83value : int(3) 84value : int(10) 85value : int(20) 86value : int(-10) 87bool(true) 88-- For protected member -- 89value : int(3) 90value : int(10) 91value : int(20) 92value : int(-10) 93bool(true) 94Done 95