helly Sun Aug 10 09:17:02 2003 EDT Added files: /spl/tests foreach_continue.phpt Log: Add foreach/continue test
Index: spl/tests/foreach_continue.phpt +++ spl/tests/foreach_continue.phpt --TEST-- SPL: foreach and break --SKIPIF-- <?php if (!extension_loaded("spl")) print "skip"; ?> --FILE-- <?php class c_iter implements spl_forward { private $obj; private $num = 0; function __construct($obj) { $this->obj = $obj; } function current() { echo __METHOD__ . "\n"; return $this->num; } function next() { echo __METHOD__ . "\n"; $this->num++; } function has_more() { $more = $this->num < $this->obj->max; echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; return $more; } } class c implements spl_iterator { public $max = 4; function new_iterator() { echo __METHOD__ . "\n"; return new c_iter($this); } } $t = new c(); foreach($t as $v) { if ($v == 0) { echo "continue outer\n"; continue; } foreach($t as $w) { if ($w == 1) { echo "continue inner\n"; continue; } if ($w == 2) { echo "break inner\n"; break; } echo "double:$v:$w\n"; } if ($v == 2) { echo "break outer\n"; break; } } print "Done\n"; ?> --EXPECT-- c::new_iterator c_iter::has_more = true c_iter::current continue outer c_iter::next c_iter::has_more = true c_iter::current c::new_iterator c_iter::has_more = true c_iter::current double:1:0 c_iter::next c_iter::has_more = true c_iter::current continue inner c_iter::next c_iter::has_more = true c_iter::current break inner c_iter::next c_iter::has_more = true c_iter::current c::new_iterator c_iter::has_more = true c_iter::current double:2:0 c_iter::next c_iter::has_more = true c_iter::current continue inner c_iter::next c_iter::has_more = true c_iter::current break inner break outer Done -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php