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--EXPECT--
59= instance method =
601 / 0 / 1 / 1
61=> 1
622 / 1 / 1 / 1
633 / 2 / 1 / 1
644 / 3 / 1 / 1
65=> 4
665 / 4 / 1 / 1
671 / 0 / 1 / 1
68=> 1
692 / 1 / 1 / 1
703 / 2 / 1 / 1
714 / 3 / 1 / 1
72=> 4
735 / 4 / 1 / 1
74 = static method =
751 / 0 / 1 / 1
76=> 1
772 / 1 / 1 / 1
783 / 2 / 1 / 1
794 / 3 / 1 / 1
80=> 4
815 / 4 / 1 / 1
821 / 0 / 1 / 1
83=> 1
842 / 1 / 1 / 1
853 / 2 / 1 / 1
864 / 3 / 1 / 1
87=> 4
885 / 4 / 1 / 1
89 = static method (2) =
901 / 0 / 1 / 1
91=> 1
922 / 1 / 1 / 1
933 / 2 / 1 / 1
944 / 3 / 1 / 1
95=> 4
965 / 4 / 1 / 1
971 / 0 / 1 / 1
98=> 1
992 / 1 / 1 / 1
1003 / 2 / 1 / 1
1014 / 3 / 1 / 1
102=> 4
1035 / 4 / 1 / 1
104 = function =
1051 / 0 / 1 / 1
106=> 1
1072 / 1 / 1 / 1
1083 / 2 / 1 / 1
1094 / 3 / 1 / 1
110=> 4
1115 / 4 / 1 / 1
1121 / 0 / 1 / 1
113=> 1
1142 / 1 / 1 / 1
1153 / 2 / 1 / 1
1164 / 3 / 1 / 1
117=> 4
1185 / 4 / 1 / 1
119 = anonymous function =
1201 / 0 / 1 / 1
121=> 1
1222 / 1 / 1 / 1
1233 / 2 / 1 / 1
1244 / 3 / 1 / 1
125=> 4
1265 / 4 / 1 / 1
1271 / 0 / 1 / 1
128=> 1
1292 / 1 / 1 / 1
1303 / 2 / 1 / 1
1314 / 3 / 1 / 1
132=> 4
1335 / 4 / 1 / 1
134