summaryrefslogtreecommitdiff
path: root/tests/classes/iterators_004.phpt
blob: 77d036a07506e8110c1d7b4f1bc03263157d5907 (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
--TEST--
ZE2 iterators must be implemented
--FILE--
<?php

echo "1st try\n";

class c1 {}

$obj = new c1();

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

echo "2nd try\n";

class c2 {

    public $max = 3;
    public $num = 0;

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

$obj = new c2();

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

print "Done\n";
?>
--EXPECT--
1st try
2nd try
object:max=>3
object:num=>0
Done