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?>
64--EXPECT--
65= instance method =
661 / 0 / 1 / 1
67=> 1
682 / 0 / 1 / 1
693 / 1 / 1 / 1
704 / 0 / 1 / 1
71=> 4
725 / 1 / 1 / 1
731 / 0 / 1 / 1
74=> 1
752 / 0 / 1 / 1
763 / 1 / 1 / 1
774 / 0 / 1 / 1
78=> 4
795 / 1 / 1 / 1
80 = static method =
811 / 0 / 1 / 1
82=> 1
832 / 0 / 1 / 1
843 / 1 / 1 / 1
854 / 0 / 1 / 1
86=> 4
875 / 1 / 1 / 1
881 / 0 / 1 / 1
89=> 1
902 / 0 / 1 / 1
913 / 1 / 1 / 1
924 / 0 / 1 / 1
93=> 4
945 / 1 / 1 / 1
95 = static method (2) =
961 / 0 / 1 / 1
97=> 1
982 / 0 / 1 / 1
993 / 1 / 1 / 1
1004 / 0 / 1 / 1
101=> 4
1025 / 1 / 1 / 1
1031 / 0 / 1 / 1
104=> 1
1052 / 0 / 1 / 1
1063 / 1 / 1 / 1
1074 / 0 / 1 / 1
108=> 4
1095 / 1 / 1 / 1
110 = function =
1111 / 0 / 1 / 1
112=> 1
1132 / 0 / 1 / 1
1143 / 1 / 1 / 1
1154 / 0 / 1 / 1
116=> 4
1175 / 1 / 1 / 1
1181 / 0 / 1 / 1
119=> 1
1202 / 0 / 1 / 1
1213 / 1 / 1 / 1
1224 / 0 / 1 / 1
123=> 4
1245 / 1 / 1 / 1
125 = anonymous function =
1261 / 0 / 1 / 1
127=> 1
1282 / 0 / 1 / 1
1293 / 1 / 1 / 1
1304 / 0 / 1 / 1
131=> 4
1325 / 1 / 1 / 1
1331 / 0 / 1 / 1
134=> 1
1352 / 0 / 1 / 1
1363 / 1 / 1 / 1
1374 / 0 / 1 / 1
138=> 4
1395 / 1 / 1 / 1
140