1--TEST-- 2IteratorAggregate::getIterator bad return type 3--FILE-- 4<?php 5 6class bad1 implements IteratorAggregate { 7 function getIterator() { 8 return null; 9 } 10} 11 12class bad2 implements IteratorAggregate { 13 function getIterator() { 14 return new stdClass; 15 } 16} 17 18class bad3 implements IteratorAggregate { 19 function getIterator() { 20 return 1; 21 } 22} 23 24class bad4 implements IteratorAggregate { 25 function getIterator() { 26 return array(1,2,3); 27 } 28} 29 30 31function f($className) { 32 try { 33 foreach (new $className as $k=>$v) { 34 echo "$k => $v\n"; 35 } 36 } catch (Exception $e) { 37 echo $e->getLine() . ": " . $e->getMessage() ."\n"; 38 } 39} 40 41f("bad1"); 42f("bad2"); 43f("bad3"); 44f("bad4"); 45 46?> 47===DONE=== 48--EXPECTF-- 4930: Objects returned by bad1::getIterator() must be traversable or implement interface Iterator 5030: Objects returned by bad2::getIterator() must be traversable or implement interface Iterator 5130: Objects returned by bad3::getIterator() must be traversable or implement interface Iterator 5230: Objects returned by bad4::getIterator() must be traversable or implement interface Iterator 53===DONE===