Annotation of embedaddon/php/tests/classes/iterators_006.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: ZE2 iterators and array wrapping
                      3: --SKIPIF--
                      4: <?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 is needed'); ?> 
                      5: --FILE--
                      6: <?php
                      7: 
                      8: class ai implements Iterator {
                      9: 
                     10:        private $array;
                     11: 
                     12:        function __construct() {
                     13:                $this->array = array('foo', 'bar', 'baz');
                     14:        }
                     15: 
                     16:        function rewind() {
                     17:                reset($this->array);
                     18:                $this->next();
                     19:        }
                     20: 
                     21:        function valid() {
                     22:                return $this->key !== NULL;
                     23:        }
                     24: 
                     25:        function key() {
                     26:                return $this->key;
                     27:        }
                     28: 
                     29:        function current() {
                     30:                return $this->current;
                     31:        }
                     32: 
                     33:        function next() {
                     34:                list($this->key, $this->current) = each($this->array);
                     35: //             list($key, $current) = each($this->array);
                     36: //             $this->key = $key;
                     37: //             $this->current = $current;
                     38:        }
                     39: }
                     40: 
                     41: class a implements IteratorAggregate {
                     42: 
                     43:        public function getIterator() {
                     44:                return new ai();
                     45:        }
                     46: }
                     47: 
                     48: $array = new a();
                     49: 
                     50: foreach ($array as $property => $value) {
                     51:        print "$property: $value\n";    
                     52: }
                     53: 
                     54: #$array = $array->getIterator();
                     55: #$array->rewind();
                     56: #$array->valid();
                     57: #var_dump($array->key());
                     58: #var_dump($array->current());
                     59: echo "===2nd===\n";
                     60: 
                     61: $array = new ai();
                     62: 
                     63: foreach ($array as $property => $value) {
                     64:        print "$property: $value\n";    
                     65: }
                     66: 
                     67: echo "===3rd===\n";
                     68: 
                     69: foreach ($array as $property => $value) {
                     70:        print "$property: $value\n";    
                     71: }
                     72: 
                     73: ?>
                     74: ===DONE===
                     75: --EXPECT--
                     76: 0: foo
                     77: 1: bar
                     78: 2: baz
                     79: ===2nd===
                     80: 0: foo
                     81: 1: bar
                     82: 2: baz
                     83: ===3rd===
                     84: 0: foo
                     85: 1: bar
                     86: 2: baz
                     87: ===DONE===

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