1--TEST-- 2Test array_walk() function : object functionality - array of objects 3--FILE-- 4<?php 5/* 6* Testing array_walk() with an array of objects 7*/ 8 9echo "*** Testing array_walk() : 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 new MyClass(3), 54 new MyClass(10), 55 new MyClass(20), 56 new MyClass(-10) 57); 58 59echo "-- For private member --\n"; 60var_dump( array_walk($input, "callback_private", 1)); 61echo "-- For public member --\n"; 62var_dump( array_walk($input, "callback_public")); 63echo "-- For protected member --\n"; 64var_dump( array_walk($input, "callback_protected")); 65 66echo "Done" 67?> 68--EXPECT-- 69*** Testing array_walk() : array of objects *** 70-- For private member -- 71value : int(3) 72key : int(0) 73value : int(10) 74key : int(1) 75value : int(20) 76key : int(2) 77value : int(-10) 78key : int(3) 79bool(true) 80-- For public member -- 81value : int(3) 82value : int(10) 83value : int(20) 84value : int(-10) 85bool(true) 86-- For protected member -- 87value : int(3) 88value : int(10) 89value : int(20) 90value : int(-10) 91bool(true) 92Done 93