summaryrefslogtreecommitdiff
path: root/ext/spl/tests/sequence.phpt
blob: 34ea7fd8d5bd8f8a38cc5672d936d85a1ae40bde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--TEST--
SPL: sequence
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
class c implements spl_iterator {

	public $max = 3;

	function newIterator() {
		echo __METHOD__ . "\n";
		return new c_iter($this);
	}
}

class c_iter implements spl_sequence_assoc {

	private $obj;
	private $num = 0;

	function __construct($obj) {
		$this->obj = $obj;
	}
	function rewind() {
		echo __METHOD__ . "\n";
		$this->num = 0;
	}
	function current() {
		echo __METHOD__ . "\n";
		return $this->num;
	}
	function next() {
		echo __METHOD__ . "\n";
		$this->num++;
	}
	function hasMore() {
		echo __METHOD__ . "\n";
		return $this->num < $this->obj->max;
	}
	function key() {
		echo __METHOD__ . "\n";
		switch($this->num) {
			case 0: return "1st";
			case 1: return "2nd";
			case 2: return "3rd";
			default: return "???";
		}
	}
}

$t = new c();
$i = $t->newIterator(); 

$implements_t = class_implements($t);
asort($implements_t);
$implements_i = class_implements($i);
asort($implements_i);

$c_info = array(get_class($t) => array('inheits' => class_parents($t), 'implements' => $implements_t),
                get_class($i) => array('inheits' => class_parents($i), 'implements' => $implements_i));
print_r($c_info);

foreach($i as $w) {
	echo "object:$w\n";
}

foreach($i as $v => $w) {
	echo "object:$v=>$w\n";
}

print "Done\n";
?>
--EXPECT--
c::newIterator
Array
(
    [c] => Array
        (
            [inheits] => Array
                (
                )

            [implements] => Array
                (
                    [spl_iterator] => spl_iterator
                )

        )

    [c_iter] => Array
        (
            [inheits] => Array
                (
                )

            [implements] => Array
                (
                    [spl_assoc] => spl_assoc
                    [spl_forward] => spl_forward
                    [spl_forward_assoc] => spl_forward_assoc
                    [spl_sequence] => spl_sequence
                    [spl_sequence_assoc] => spl_sequence_assoc
                )

        )

)
c_iter::rewind
c_iter::hasMore
c_iter::current
c_iter::key
object:0
c_iter::next
c_iter::hasMore
c_iter::current
c_iter::key
object:1
c_iter::next
c_iter::hasMore
c_iter::current
c_iter::key
object:2
c_iter::next
c_iter::hasMore
c_iter::rewind
c_iter::hasMore
c_iter::current
c_iter::key
object:1st=>0
c_iter::next
c_iter::hasMore
c_iter::current
c_iter::key
object:2nd=>1
c_iter::next
c_iter::hasMore
c_iter::current
c_iter::key
object:3rd=>2
c_iter::next
c_iter::hasMore
Done