1--TEST-- 2SPL: RecursiveIteratorIterator and beginChildren/endChildren 3--FILE-- 4<?php 5 6class 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 28class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator 29{ 30 function rewind() 31 { 32 echo __METHOD__ . "\n"; 33 parent::rewind(); 34 } 35 36 function valid() 37 { 38 echo __METHOD__ . "\n"; 39 return parent::valid(); 40 } 41 42 function current() 43 { 44 echo __METHOD__ . "\n"; 45 return parent::current(); 46 } 47 48 function key() 49 { 50 echo __METHOD__ . "\n"; 51 return parent::key(); 52 } 53 54 function next() 55 { 56 echo __METHOD__ . "\n"; 57 parent::next(); 58 } 59 60 function beginChildren() 61 { 62 echo __METHOD__ . "(".$this->getDepth().")\n"; 63 } 64 65 function endChildren() 66 { 67 echo __METHOD__ . "(".$this->getDepth().")\n"; 68 } 69} 70 71foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"))) as $k=>$v) 72{ 73 echo "$k=>$v\n"; 74} 75?> 76--EXPECT-- 77RecursiveArrayIteratorIterator::rewind 78RecursiveArrayIteratorIterator::valid 79RecursiveArrayIteratorIterator::current 80RecursiveArrayIteratorIterator::key 810=>a 82RecursiveArrayIteratorIterator::next 83MyRecursiveArrayIterator::getChildren 84RecursiveArrayIteratorIterator::beginChildren(1) 85RecursiveArrayIteratorIterator::valid 86RecursiveArrayIteratorIterator::current 87RecursiveArrayIteratorIterator::key 880=>ba 89RecursiveArrayIteratorIterator::next 90MyRecursiveArrayIterator::getChildren 91RecursiveArrayIteratorIterator::beginChildren(2) 92RecursiveArrayIteratorIterator::valid 93RecursiveArrayIteratorIterator::current 94RecursiveArrayIteratorIterator::key 950=>bba 96RecursiveArrayIteratorIterator::next 97RecursiveArrayIteratorIterator::valid 98RecursiveArrayIteratorIterator::current 99RecursiveArrayIteratorIterator::key 1001=>bbb 101RecursiveArrayIteratorIterator::next 102MyRecursiveArrayIterator::valid = false 103RecursiveArrayIteratorIterator::endChildren(2) 104MyRecursiveArrayIterator::getChildren 105RecursiveArrayIteratorIterator::beginChildren(2) 106MyRecursiveArrayIterator::getChildren 107RecursiveArrayIteratorIterator::beginChildren(3) 108RecursiveArrayIteratorIterator::valid 109RecursiveArrayIteratorIterator::current 110RecursiveArrayIteratorIterator::key 1110=>bcaa 112RecursiveArrayIteratorIterator::next 113MyRecursiveArrayIterator::valid = false 114RecursiveArrayIteratorIterator::endChildren(3) 115MyRecursiveArrayIterator::valid = false 116RecursiveArrayIteratorIterator::endChildren(2) 117MyRecursiveArrayIterator::valid = false 118RecursiveArrayIteratorIterator::endChildren(1) 119MyRecursiveArrayIterator::getChildren 120RecursiveArrayIteratorIterator::beginChildren(1) 121RecursiveArrayIteratorIterator::valid 122RecursiveArrayIteratorIterator::current 123RecursiveArrayIteratorIterator::key 1240=>ca 125RecursiveArrayIteratorIterator::next 126MyRecursiveArrayIterator::valid = false 127RecursiveArrayIteratorIterator::endChildren(1) 128RecursiveArrayIteratorIterator::valid 129RecursiveArrayIteratorIterator::current 130RecursiveArrayIteratorIterator::key 1313=>d 132RecursiveArrayIteratorIterator::next 133MyRecursiveArrayIterator::valid = false 134RecursiveArrayIteratorIterator::valid 135MyRecursiveArrayIterator::valid = false 136