xref: /PHP-5.3/tests/classes/iterators_006.phpt (revision b6b7c9eb)
1--TEST--
2ZE2 iterators and array wrapping
3--SKIPIF--
4<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?>
5--FILE--
6<?php
7
8class ai implements Iterator {
9
10	private $array;
11
12	function __construct() {
13		$this->array = array('foo', 'bar', 'baz');
14	}
15
16	function rewind() {
17		reset($this->array);
18		$this->next();
19	}
20
21	function valid() {
22		return $this->key !== NULL;
23	}
24
25	function key() {
26		return $this->key;
27	}
28
29	function current() {
30		return $this->current;
31	}
32
33	function next() {
34		list($this->key, $this->current) = each($this->array);
35//		list($key, $current) = each($this->array);
36//		$this->key = $key;
37//		$this->current = $current;
38	}
39}
40
41class a implements IteratorAggregate {
42
43	public function getIterator() {
44		return new ai();
45	}
46}
47
48$array = new a();
49
50foreach ($array as $property => $value) {
51	print "$property: $value\n";
52}
53
54#$array = $array->getIterator();
55#$array->rewind();
56#$array->valid();
57#var_dump($array->key());
58#var_dump($array->current());
59echo "===2nd===\n";
60
61$array = new ai();
62
63foreach ($array as $property => $value) {
64	print "$property: $value\n";
65}
66
67echo "===3rd===\n";
68
69foreach ($array as $property => $value) {
70	print "$property: $value\n";
71}
72
73?>
74===DONE===
75--EXPECT--
760: foo
771: bar
782: baz
79===2nd===
800: foo
811: bar
822: baz
83===3rd===
840: foo
851: bar
862: baz
87===DONE===