1--TEST-- 2SPL: iterator_apply() 3--FILE-- 4<?php 5 6function my_error_handler($errno, $errstr, $errfile, $errline) { 7 echo "Error: $errstr\n"; 8} 9 10set_error_handler('my_error_handler'); 11 12function test_arg($arg) 13{ 14 if ($arg instanceof Iterator) 15 { 16 var_dump($arg->key()); 17 var_dump($arg->current()); 18 } 19 else 20 { 21 var_dump($arg); 22 } 23 return true; 24} 25 26function test() 27{ 28 static $arg = 0; 29 var_dump($arg++); 30 return true; 31} 32 33$it = new RecursiveArrayIterator(array(1, array(21, 22), 3)); 34 35var_dump(iterator_apply($it, 'test', NULL)); 36 37echo "===ARGS===\n"; 38var_dump(iterator_apply($it, 'test_arg', array($it))); 39 40echo "===RECURSIVE===\n"; 41$it = new RecursiveIteratorIterator($it); 42var_dump(iterator_apply($it, 'test')); 43 44echo "===ERRORS===\n"; 45var_dump(iterator_apply($it, 'test', 1)); 46var_dump(iterator_apply($it, 'non_existing_function')); 47var_dump(iterator_apply($it, 'non_existing_function', NULL, 2)); 48 49?> 50===DONE=== 51<?php exit(0); ?> 52--EXPECT-- 53int(0) 54int(1) 55int(2) 56int(3) 57===ARGS=== 58int(0) 59int(1) 60int(1) 61array(2) { 62 [0]=> 63 int(21) 64 [1]=> 65 int(22) 66} 67int(2) 68int(3) 69int(3) 70===RECURSIVE=== 71int(3) 72int(4) 73int(5) 74int(6) 75int(4) 76===ERRORS=== 77Error: Argument 3 passed to iterator_apply() must be of the type array, integer given 78Error: iterator_apply() expects parameter 3 to be array, integer given 79NULL 80Error: iterator_apply() expects parameter 2 to be a valid callback, function 'non_existing_function' not found or invalid function name 81NULL 82Error: iterator_apply() expects at most 3 parameters, 4 given 83NULL 84===DONE=== 85