Annotation of embedaddon/php/tests/classes/iterators_007.phpt, revision 1.1
1.1 ! misho 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>