Annotation of embedaddon/php/tests/classes/iterators_003.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: ZE2 iterators and break
! 3: --SKIPIF--
! 4: <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
! 5: --FILE--
! 6: <?php
! 7: class c_iter implements Iterator {
! 8:
! 9: private $obj;
! 10: private $num = 0;
! 11:
! 12: function __construct($obj) {
! 13: echo __METHOD__ . "\n";
! 14: $this->obj = $obj;
! 15: }
! 16: function rewind() {
! 17: echo __METHOD__ . "\n";
! 18: }
! 19: function valid() {
! 20: $more = $this->num < $this->obj->max;
! 21: echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
! 22: return $more;
! 23: }
! 24: function current() {
! 25: echo __METHOD__ . "\n";
! 26: return $this->num;
! 27: }
! 28: function next() {
! 29: echo __METHOD__ . "\n";
! 30: $this->num++;
! 31: }
! 32: function key() {
! 33: return $this->num;
! 34: }
! 35: }
! 36:
! 37: class c implements IteratorAggregate {
! 38:
! 39: public $max = 4;
! 40:
! 41: function getIterator() {
! 42: echo __METHOD__ . "\n";
! 43: return new c_iter($this);
! 44: }
! 45: }
! 46:
! 47: $t = new c();
! 48:
! 49: foreach($t as $v) {
! 50: if ($v == 0) {
! 51: echo "continue outer\n";
! 52: continue;
! 53: }
! 54: foreach($t as $w) {
! 55: if ($w == 1) {
! 56: echo "continue inner\n";
! 57: continue;
! 58: }
! 59: if ($w == 2) {
! 60: echo "break inner\n";
! 61: break;
! 62: }
! 63: echo "double:$v:$w\n";
! 64: }
! 65: if ($v == 2) {
! 66: echo "break outer\n";
! 67: break;
! 68: }
! 69: }
! 70:
! 71: print "Done\n";
! 72: ?>
! 73: --EXPECT--
! 74: c::getIterator
! 75: c_iter::__construct
! 76: c_iter::rewind
! 77: c_iter::valid = true
! 78: c_iter::current
! 79: continue outer
! 80: c_iter::next
! 81: c_iter::valid = true
! 82: c_iter::current
! 83: c::getIterator
! 84: c_iter::__construct
! 85: c_iter::rewind
! 86: c_iter::valid = true
! 87: c_iter::current
! 88: double:1:0
! 89: c_iter::next
! 90: c_iter::valid = true
! 91: c_iter::current
! 92: continue inner
! 93: c_iter::next
! 94: c_iter::valid = true
! 95: c_iter::current
! 96: break inner
! 97: c_iter::next
! 98: c_iter::valid = true
! 99: c_iter::current
! 100: c::getIterator
! 101: c_iter::__construct
! 102: c_iter::rewind
! 103: c_iter::valid = true
! 104: c_iter::current
! 105: double:2:0
! 106: c_iter::next
! 107: c_iter::valid = true
! 108: c_iter::current
! 109: continue inner
! 110: c_iter::next
! 111: c_iter::valid = true
! 112: c_iter::current
! 113: break inner
! 114: break outer
! 115: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>