Add foreach/continue test

This commit is contained in:
Marcus Boerger 2003-08-10 13:17:02 +00:00
parent 2a13d3f9f7
commit 142c79d653

View File

@ -0,0 +1,102 @@
--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