Annotation of embedaddon/php/tests/classes/iterators_002.phpt, revision 1.1.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:                $this->num = 0;
                     19:        }
                     20:        function valid() {
                     21:                $more = $this->num < $this->obj->max;
                     22:                echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n";
                     23:                return $more;
                     24:        }
                     25:        function current() {
                     26:                echo __METHOD__ . "\n";
                     27:                return $this->num;
                     28:        }
                     29:        function next() {
                     30:                echo __METHOD__ . "\n";
                     31:                $this->num++;
                     32:        }
                     33:        function key() {
                     34:                echo __METHOD__ . "\n";
                     35:                switch($this->num) {
                     36:                        case 0: return "1st";
                     37:                        case 1: return "2nd";
                     38:                        case 2: return "3rd";
                     39:                        default: return "???";
                     40:                }
                     41:        }
                     42:        function __destruct() {
                     43:                echo __METHOD__ . "\n";
                     44:        }
                     45: }
                     46:        
                     47: class c implements IteratorAggregate {
                     48: 
                     49:        public $max = 3;
                     50: 
                     51:        function getIterator() {
                     52:                echo __METHOD__ . "\n";
                     53:                return new c_iter($this);
                     54:        }
                     55:        function __destruct() {
                     56:                echo __METHOD__ . "\n";
                     57:        }
                     58: }
                     59: 
                     60: $t = new c();
                     61: 
                     62: foreach($t as $k => $v) {
                     63:        foreach($t as $w) {
                     64:                echo "double:$v:$w\n";
                     65:                break;
                     66:        }
                     67: }
                     68: 
                     69: unset($t);
                     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: c_iter::key
                     80: c::getIterator
                     81: c_iter::__construct
                     82: c_iter::rewind
                     83: c_iter::valid = true
                     84: c_iter::current
                     85: double:0:0
                     86: c_iter::__destruct
                     87: c_iter::next
                     88: c_iter::valid = true
                     89: c_iter::current
                     90: c_iter::key
                     91: c::getIterator
                     92: c_iter::__construct
                     93: c_iter::rewind
                     94: c_iter::valid = true
                     95: c_iter::current
                     96: double:1:0
                     97: c_iter::__destruct
                     98: c_iter::next
                     99: c_iter::valid = true
                    100: c_iter::current
                    101: c_iter::key
                    102: c::getIterator
                    103: c_iter::__construct
                    104: c_iter::rewind
                    105: c_iter::valid = true
                    106: c_iter::current
                    107: double:2:0
                    108: c_iter::__destruct
                    109: c_iter::next
                    110: c_iter::valid = false
                    111: c_iter::__destruct
                    112: c::__destruct
                    113: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>