1--TEST--
2RecursiveCallbackFilterIterator
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	if ($inner->hasChildren()) {
20		return true;
21	}
22	printf("%s / %s / %d / %d\n"
23		, print_r($value, true)
24		, $key
25		, $value == $inner->current()
26		, $key == $inner->key()
27	);
28	return $value === 1 || $value === 4;
29}
30
31$tests = array(
32    'instance method'    => function() { return array(new A, 'test'); },
33    'static method'      => function() { return array('B', 'test'); },
34    'static method (2)'  => function() { return 'B::test'; },
35    'function'           => function() { return 'test'; },
36    'anonymous function' => function() { return function($value, $key, $inner) { return test($value, $key, $inner); }; },
37);
38
39foreach($tests as $name => $test) {
40
41    $callback = $test();
42    $it = new RecursiveArrayIterator(array(1, array(2, 3), array(4, 5)));
43    $it = new RecursiveCallbackFilterIterator($it, $callback);
44	$it = new RecursiveIteratorIterator($it);
45
46    echo " = $name =\n";
47
48    foreach($it as $value) {
49        echo "=> $value\n";
50    }
51
52	// same test, with no reference to callback
53
54    $it = new RecursiveArrayIterator(array(1, array(2, 3), array(4, 5)));
55    $it = new RecursiveCallbackFilterIterator($it, $test());
56	$it = new RecursiveIteratorIterator($it);
57    unset($callback);
58
59    foreach($it as $value) {
60        echo "=> $value\n";
61    }
62}
63--EXPECT--
64= instance method =
651 / 0 / 1 / 1
66=> 1
672 / 0 / 1 / 1
683 / 1 / 1 / 1
694 / 0 / 1 / 1
70=> 4
715 / 1 / 1 / 1
721 / 0 / 1 / 1
73=> 1
742 / 0 / 1 / 1
753 / 1 / 1 / 1
764 / 0 / 1 / 1
77=> 4
785 / 1 / 1 / 1
79 = static method =
801 / 0 / 1 / 1
81=> 1
822 / 0 / 1 / 1
833 / 1 / 1 / 1
844 / 0 / 1 / 1
85=> 4
865 / 1 / 1 / 1
871 / 0 / 1 / 1
88=> 1
892 / 0 / 1 / 1
903 / 1 / 1 / 1
914 / 0 / 1 / 1
92=> 4
935 / 1 / 1 / 1
94 = static method (2) =
951 / 0 / 1 / 1
96=> 1
972 / 0 / 1 / 1
983 / 1 / 1 / 1
994 / 0 / 1 / 1
100=> 4
1015 / 1 / 1 / 1
1021 / 0 / 1 / 1
103=> 1
1042 / 0 / 1 / 1
1053 / 1 / 1 / 1
1064 / 0 / 1 / 1
107=> 4
1085 / 1 / 1 / 1
109 = function =
1101 / 0 / 1 / 1
111=> 1
1122 / 0 / 1 / 1
1133 / 1 / 1 / 1
1144 / 0 / 1 / 1
115=> 4
1165 / 1 / 1 / 1
1171 / 0 / 1 / 1
118=> 1
1192 / 0 / 1 / 1
1203 / 1 / 1 / 1
1214 / 0 / 1 / 1
122=> 4
1235 / 1 / 1 / 1
124 = anonymous function =
1251 / 0 / 1 / 1
126=> 1
1272 / 0 / 1 / 1
1283 / 1 / 1 / 1
1294 / 0 / 1 / 1
130=> 4
1315 / 1 / 1 / 1
1321 / 0 / 1 / 1
133=> 1
1342 / 0 / 1 / 1
1353 / 1 / 1 / 1
1364 / 0 / 1 / 1
137=> 4
1385 / 1 / 1 / 1
139