File:
[ELWIX - Embedded LightWeight unIX -] /
embedaddon /
php /
tests /
classes /
iterators_007.phpt
Revision
1.1.1.1 (vendor branch):
download - view:
text,
annotated -
select for diffs -
revision graph
Tue Feb 21 23:48:06 2012 UTC (12 years, 4 months ago) by
misho
Branches:
php,
MAIN
CVS tags:
v5_4_3elwix,
v5_4_29p0,
v5_4_29,
v5_4_20p0,
v5_4_20,
v5_4_17p0,
v5_4_17,
v5_3_10,
HEAD
php
1: --TEST--
2: ZE2 iterators and exceptions
3: --FILE--
4: <?php
5: class Test implements Iterator
6: {
7: public $arr = array(1, 2, 3);
8: public $x = 0;
9:
10: public function rewind() { if ($this->x == 0) throw new Exception(__METHOD__); reset($this->arr); }
11: public function current() { if ($this->x == 1) throw new Exception(__METHOD__); return current($this->arr); }
12: public function key() { if ($this->x == 2) throw new Exception(__METHOD__); return key($this->arr); }
13: public function next() { if ($this->x == 3) throw new Exception(__METHOD__); next($this->arr); }
14: public function valid() { if ($this->x == 4) throw new Exception(__METHOD__); return (key($this->arr) !== NULL); }
15: }
16:
17: $t = new Test();
18:
19: while($t->x < 5)
20: {
21: try
22: {
23: foreach($t as $k => $v)
24: {
25: echo "Current\n";
26: }
27: }
28: catch(Exception $e)
29: {
30: echo "Caught in " . $e->getMessage() . "()\n";
31: }
32: $t->x++;
33: }
34: ?>
35: ===DONE===
36: --EXPECT--
37: Caught in Test::rewind()
38: Caught in Test::current()
39: Caught in Test::key()
40: Current
41: Caught in Test::next()
42: Caught in Test::valid()
43: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>