summaryrefslogtreecommitdiff
path: root/tests/php/include/valueiterator/1.php
blob: 984a77f282fbf651e6a05233d3b6edb6fc585325 (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
<?php

class SimpleClass {
    public    $cl0_float = 3.14;
    public    $cl0_str1  = 'public str1';
    private   $cl0_str2  = 'private str2';
    protected $cl0_str3  = 'protected str3';
}

class impIterator implements Iterator {
    private $position = 0;
    private $array = array(
        "firstElement",
        "secondElement",
        "lastelEment",
    );  

    public function __construct() {
        $this->position = 0;
    }

    function rewind() {
        $this->position = 0;
    }

    function current() {
        return $this->array[$this->position];
    }

    function key() {
        return 'key_' . $this->position;
    }

    function next() {
        ++$this->position;
    }

    function valid() {
        return isset($this->array[$this->position]);
    }
    
    function __destruct() {
        echo "~impIterator\n";
    }
}

class impIterAggr1 implements IteratorAggregate {
    public function getIterator() {
        return new ArrayIterator(new SimpleClass);
    }
    function __destruct() {
        echo "~impIterAggr1\n";
    }
}

class impIterAggr2 implements IteratorAggregate {
    public function getIterator() {
        return new impIterator();
    }
    function __destruct() {
        echo "~impIterAggr2\n";
    }
}