Annotation of embedaddon/php/ext/spl/tests/iterator_034.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: SPL: RecursiveIteratorIterator and break deep
                      3: --FILE--
                      4: <?php
                      5: 
                      6: class MyRecursiveArrayIterator extends RecursiveArrayIterator
                      7: {
                      8:        function valid()
                      9:        {
                     10:                if (!parent::valid())
                     11:                {
                     12:                        echo __METHOD__ . "() = false\n";
                     13:                        return false;
                     14:                }
                     15:                else
                     16:                {
                     17:                        return true;
                     18:                }
                     19:        }
                     20: 
                     21:        function getChildren()
                     22:        {
                     23:                echo __METHOD__ . "()\n";
                     24:                return parent::getChildren();
                     25:        }
                     26:        
                     27:        function rewind()
                     28:        {
                     29:                echo __METHOD__ . "()\n";
                     30:                parent::rewind();
                     31:        }
                     32: }
                     33: 
                     34: class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
                     35: {
                     36:        private $max_depth;
                     37:        private $over = 0;
                     38: 
                     39:        function __construct($it, $max_depth)
                     40:        {
                     41:                $this->max_depth = $max_depth;
                     42:                parent::__construct($it);
                     43:        }
                     44: 
                     45:        function rewind()
                     46:        {
                     47:                echo __METHOD__ . "() - BEGIN\n";
                     48:                parent::rewind();
                     49:                echo __METHOD__ . "() - DONE\n";
                     50:        }
                     51: 
                     52:        function valid()
                     53:        {
                     54:                echo __METHOD__ . "()\n";
                     55:                return parent::valid();
                     56:        }
                     57: 
                     58:        function current()
                     59:        {
                     60:                echo __METHOD__ . "()\n";
                     61:                return parent::current();
                     62:        }
                     63: 
                     64:        function key()
                     65:        {
                     66:                echo __METHOD__ . "()\n";
                     67:                return parent::key();
                     68:        }
                     69: 
                     70:        function next()
                     71:        {
                     72:                echo __METHOD__ . "()\n";
                     73:                parent::next();
                     74:        }
                     75: 
                     76:        function callHasChildren()
                     77:        {
                     78:                $has = parent::callHasChildren();
                     79:                $res = $this->getDepth() < $this->max_depth && $has;
                     80:                echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n";
                     81:                return $res;
                     82:        }
                     83: 
                     84:        function beginChildren()
                     85:        {
                     86:                echo __METHOD__ . "(".$this->getDepth().")\n";
                     87:                parent::beginChildren();
                     88:        }
                     89: 
                     90:        function endChildren()
                     91:        {
                     92:                echo __METHOD__ . "(".$this->getDepth().")\n";
                     93:                parent::endChildren();
                     94:        }
                     95: }
                     96: 
                     97: $p = 0;
                     98: $it = new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2);
                     99: foreach($it as $k=>$v)
                    100: {
                    101:        if (is_array($v)) $v = join('',$v);
                    102:        echo "$k=>$v\n";
                    103:        if ($p++ == 5)
                    104:        {
                    105:                echo "===BREAK===\n";
                    106:                break;
                    107:        }
                    108: }
                    109: 
                    110: echo "===FOREND===\n";
                    111: 
                    112: $it->rewind();
                    113: 
                    114: echo "===CHECK===\n";
                    115: 
                    116: var_dump($it->valid());
                    117: var_dump($it->current() == "a");
                    118: 
                    119: ?>
                    120: ===DONE===
                    121: <?php exit(0); ?>
                    122: --EXPECT--
                    123: RecursiveArrayIteratorIterator::rewind() - BEGIN
                    124: MyRecursiveArrayIterator::rewind()
                    125: RecursiveArrayIteratorIterator::callHasChildren(0) = no/no
                    126: RecursiveArrayIteratorIterator::rewind() - DONE
                    127: RecursiveArrayIteratorIterator::valid()
                    128: RecursiveArrayIteratorIterator::current()
                    129: RecursiveArrayIteratorIterator::key()
                    130: 0=>a
                    131: RecursiveArrayIteratorIterator::next()
                    132: RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes
                    133: MyRecursiveArrayIterator::getChildren()
                    134: MyRecursiveArrayIterator::rewind()
                    135: RecursiveArrayIteratorIterator::beginChildren(1)
                    136: RecursiveArrayIteratorIterator::callHasChildren(1) = no/no
                    137: RecursiveArrayIteratorIterator::valid()
                    138: RecursiveArrayIteratorIterator::current()
                    139: RecursiveArrayIteratorIterator::key()
                    140: 0=>ba
                    141: RecursiveArrayIteratorIterator::next()
                    142: RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes
                    143: MyRecursiveArrayIterator::getChildren()
                    144: MyRecursiveArrayIterator::rewind()
                    145: RecursiveArrayIteratorIterator::beginChildren(2)
                    146: RecursiveArrayIteratorIterator::callHasChildren(2) = no/no
                    147: RecursiveArrayIteratorIterator::valid()
                    148: RecursiveArrayIteratorIterator::current()
                    149: RecursiveArrayIteratorIterator::key()
                    150: 0=>bba
                    151: RecursiveArrayIteratorIterator::next()
                    152: RecursiveArrayIteratorIterator::callHasChildren(2) = no/no
                    153: RecursiveArrayIteratorIterator::valid()
                    154: RecursiveArrayIteratorIterator::current()
                    155: RecursiveArrayIteratorIterator::key()
                    156: 1=>bbb
                    157: RecursiveArrayIteratorIterator::next()
                    158: MyRecursiveArrayIterator::valid() = false
                    159: RecursiveArrayIteratorIterator::endChildren(2)
                    160: RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes
                    161: MyRecursiveArrayIterator::getChildren()
                    162: MyRecursiveArrayIterator::rewind()
                    163: RecursiveArrayIteratorIterator::beginChildren(2)
                    164: RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes
                    165: RecursiveArrayIteratorIterator::valid()
                    166: RecursiveArrayIteratorIterator::current()
                    167: RecursiveArrayIteratorIterator::key()
                    168: 0=>bcaa
                    169: RecursiveArrayIteratorIterator::next()
                    170: RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes
                    171: RecursiveArrayIteratorIterator::valid()
                    172: RecursiveArrayIteratorIterator::current()
                    173: RecursiveArrayIteratorIterator::key()
                    174: 1=>bcba
                    175: ===BREAK===
                    176: ===FOREND===
                    177: RecursiveArrayIteratorIterator::rewind() - BEGIN
                    178: RecursiveArrayIteratorIterator::endChildren(1)
                    179: RecursiveArrayIteratorIterator::endChildren(0)
                    180: MyRecursiveArrayIterator::rewind()
                    181: RecursiveArrayIteratorIterator::callHasChildren(0) = no/no
                    182: RecursiveArrayIteratorIterator::rewind() - DONE
                    183: ===CHECK===
                    184: RecursiveArrayIteratorIterator::valid()
                    185: bool(true)
                    186: RecursiveArrayIteratorIterator::current()
                    187: bool(true)
                    188: ===DONE===

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