Annotation of embedaddon/php/tests/lang/foreachLoopIteratorAggregate.004.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Duplicate of zend test tests/classes/iterators_002.phpt without expected output from destructor
! 3: --FILE--
! 4: <?php
! 5: class c_iter implements Iterator {
! 6:
! 7: private $obj;
! 8: private $num = 0;
! 9:
! 10: function __construct($obj) {
! 11: echo __METHOD__ . "\n";
! 12: $this->obj = $obj;
! 13: }
! 14: function rewind() {
! 15: echo __METHOD__ . "\n";
! 16: $this->num = 0;
! 17: }
! 18: function valid() {
! 19: $more = $this->num < $this->obj->max;
! 20: echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
! 21: return $more;
! 22: }
! 23: function current() {
! 24: echo __METHOD__ . "\n";
! 25: return $this->num;
! 26: }
! 27: function next() {
! 28: echo __METHOD__ . "\n";
! 29: $this->num++;
! 30: }
! 31: function key() {
! 32: echo __METHOD__ . "\n";
! 33: switch($this->num) {
! 34: case 0: return "1st";
! 35: case 1: return "2nd";
! 36: case 2: return "3rd";
! 37: default: return "???";
! 38: }
! 39: }
! 40: function __destruct() {
! 41: }
! 42: }
! 43:
! 44: class c implements IteratorAggregate {
! 45:
! 46: public $max = 3;
! 47:
! 48: function getIterator() {
! 49: echo __METHOD__ . "\n";
! 50: return new c_iter($this);
! 51: }
! 52: function __destruct() {
! 53: }
! 54: }
! 55:
! 56: $t = new c();
! 57:
! 58: foreach($t as $k => $v) {
! 59: foreach($t as $w) {
! 60: echo "double:$v:$w\n";
! 61: break;
! 62: }
! 63: }
! 64:
! 65: unset($t);
! 66:
! 67: ?>
! 68: ===DONE===
! 69: --EXPECT--
! 70: c::getIterator
! 71: c_iter::__construct
! 72: c_iter::rewind
! 73: c_iter::valid = true
! 74: c_iter::current
! 75: c_iter::key
! 76: c::getIterator
! 77: c_iter::__construct
! 78: c_iter::rewind
! 79: c_iter::valid = true
! 80: c_iter::current
! 81: double:0:0
! 82: c_iter::next
! 83: c_iter::valid = true
! 84: c_iter::current
! 85: c_iter::key
! 86: c::getIterator
! 87: c_iter::__construct
! 88: c_iter::rewind
! 89: c_iter::valid = true
! 90: c_iter::current
! 91: double:1:0
! 92: c_iter::next
! 93: c_iter::valid = true
! 94: c_iter::current
! 95: c_iter::key
! 96: c::getIterator
! 97: c_iter::__construct
! 98: c_iter::rewind
! 99: c_iter::valid = true
! 100: c_iter::current
! 101: double:2:0
! 102: c_iter::next
! 103: c_iter::valid = false
! 104: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>