1--TEST-- 2CallbackFilterIterator 3--FILE-- 4<?php 5 6class A { 7 function test($value, $key, $inner) { 8 return test($value, $key, $inner); 9 } 10} 11 12class B { 13 static function test($value, $key, $inner) { 14 return test($value, $key, $inner); 15 } 16} 17 18function test($value, $key, $inner) { 19 printf("%s / %s / %d / %d\n" 20 , $value 21 , $key 22 , $value == $inner->current() 23 , $key == $inner->key() 24 ); 25 return $value === 1 || $value === 4; 26} 27 28$tests = array( 29 'instance method' => function() { return array(new A, 'test'); }, 30 'static method' => function() { return array('B', 'test'); }, 31 'static method (2)' => function() { return 'B::test'; }, 32 'function' => function() { return 'test'; }, 33 'anonymous function' => function() { return function($value, $key, $inner) { return test($value, $key, $inner); }; }, 34); 35 36foreach($tests as $name => $test) { 37 38 $callback = $test(); 39 $it = new ArrayIterator(range(1, 5)); 40 $it = new CallbackFilterIterator($it, $callback); 41 42 echo " = $name =\n"; 43 44 foreach($it as $value) { 45 echo "=> $value\n"; 46 } 47 48 // same test, with no reference to callback 49 50 $it = new ArrayIterator(range(1, 5)); 51 $it = new CallbackFilterIterator($it, $test()); 52 unset($callback); 53 54 foreach($it as $value) { 55 echo "=> $value\n"; 56 } 57} 58?> 59--EXPECT-- 60= instance method = 611 / 0 / 1 / 1 62=> 1 632 / 1 / 1 / 1 643 / 2 / 1 / 1 654 / 3 / 1 / 1 66=> 4 675 / 4 / 1 / 1 681 / 0 / 1 / 1 69=> 1 702 / 1 / 1 / 1 713 / 2 / 1 / 1 724 / 3 / 1 / 1 73=> 4 745 / 4 / 1 / 1 75 = static method = 761 / 0 / 1 / 1 77=> 1 782 / 1 / 1 / 1 793 / 2 / 1 / 1 804 / 3 / 1 / 1 81=> 4 825 / 4 / 1 / 1 831 / 0 / 1 / 1 84=> 1 852 / 1 / 1 / 1 863 / 2 / 1 / 1 874 / 3 / 1 / 1 88=> 4 895 / 4 / 1 / 1 90 = static method (2) = 911 / 0 / 1 / 1 92=> 1 932 / 1 / 1 / 1 943 / 2 / 1 / 1 954 / 3 / 1 / 1 96=> 4 975 / 4 / 1 / 1 981 / 0 / 1 / 1 99=> 1 1002 / 1 / 1 / 1 1013 / 2 / 1 / 1 1024 / 3 / 1 / 1 103=> 4 1045 / 4 / 1 / 1 105 = function = 1061 / 0 / 1 / 1 107=> 1 1082 / 1 / 1 / 1 1093 / 2 / 1 / 1 1104 / 3 / 1 / 1 111=> 4 1125 / 4 / 1 / 1 1131 / 0 / 1 / 1 114=> 1 1152 / 1 / 1 / 1 1163 / 2 / 1 / 1 1174 / 3 / 1 / 1 118=> 4 1195 / 4 / 1 / 1 120 = anonymous function = 1211 / 0 / 1 / 1 122=> 1 1232 / 1 / 1 / 1 1243 / 2 / 1 / 1 1254 / 3 / 1 / 1 126=> 4 1275 / 4 / 1 / 1 1281 / 0 / 1 / 1 129=> 1 1302 / 1 / 1 / 1 1313 / 2 / 1 / 1 1324 / 3 / 1 / 1 133=> 4 1345 / 4 / 1 / 1 135