1--TEST-- 2SPL: RecursiveIteratorIterator and setMaxDepth() 3--FILE-- 4<?php 5 6$ar = array(1, 2, array(31, 32, array(331, array(3321, array(33221)))), 4); 7 8$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($ar)); 9 10echo "===?===\n"; 11var_dump($it->getMaxDepth()); 12foreach($it as $v) echo $it->getDepth() . ": $v\n"; 13 14echo "===2===\n"; 15$it->setMaxDepth(2); 16var_dump($it->getMaxDepth()); 17foreach($it as $v) echo $it->getDepth() . ": $v\n"; 18 19echo "===X===\n"; 20$it->setMaxDepth(); 21var_dump($it->getMaxDepth()); 22foreach($it as $v) echo $it->getDepth() . ": $v\n"; 23 24echo "===3===\n"; 25$it->setMaxDepth(3); 26var_dump($it->getMaxDepth()); 27foreach($it as $v) echo $it->getDepth() . ": $v\n"; 28 29echo "===5===\n"; 30$it->setMaxDepth(5); 31var_dump($it->getMaxDepth()); 32foreach($it as $v) echo $it->getDepth() . ": $v\n"; 33 34echo "===0===\n"; 35$it->setMaxDepth(0); 36var_dump($it->getMaxDepth()); 37foreach($it as $v) echo $it->getDepth() . ": $v\n"; 38 39echo "===-1===\n"; 40$it->setMaxDepth(-1); 41var_dump($it->getMaxDepth()); 42try 43{ 44 $it->setMaxDepth(4); 45 $it->setMaxDepth(-2); 46} 47catch(Exception $e) 48{ 49 var_dump($e->getMessage()); 50} 51var_dump($it->getMaxDepth()); 52?> 53===DONE=== 54<?php exit(0); ?> 55--EXPECT-- 56===?=== 57bool(false) 580: 1 590: 2 601: 31 611: 32 622: 331 633: 3321 644: 33221 650: 4 66===2=== 67int(2) 680: 1 690: 2 701: 31 711: 32 722: 331 730: 4 74===X=== 75bool(false) 760: 1 770: 2 781: 31 791: 32 802: 331 813: 3321 824: 33221 830: 4 84===3=== 85int(3) 860: 1 870: 2 881: 31 891: 32 902: 331 913: 3321 920: 4 93===5=== 94int(5) 950: 1 960: 2 971: 31 981: 32 992: 331 1003: 3321 1014: 33221 1020: 4 103===0=== 104int(0) 1050: 1 1060: 2 1070: 4 108===-1=== 109bool(false) 110string(33) "Parameter max_depth must be >= -1" 111int(4) 112===DONE=== 113