parent
c9d6e93f40
commit
749b4ec00d
3 changed files with 126 additions and 7 deletions
@ -0,0 +1,115 @@ |
||||
--TEST-- |
||||
ZE2 iterators and break |
||||
--FILE-- |
||||
<?php |
||||
class c_iter implements Iterator { |
||||
|
||||
private $obj; |
||||
private $num = 0; |
||||
|
||||
function __construct($obj) { |
||||
echo __METHOD__ . "\n"; |
||||
$this->obj = $obj; |
||||
} |
||||
function rewind(): void { |
||||
echo __METHOD__ . "\n"; |
||||
} |
||||
function valid(): bool { |
||||
$more = $this->num < $this->obj->max; |
||||
echo __METHOD__ . ' = ' .($more ? 'true' : 'false') . "\n"; |
||||
return $more; |
||||
} |
||||
function current(): mixed { |
||||
echo __METHOD__ . "\n"; |
||||
return $this->num; |
||||
} |
||||
function next(): void { |
||||
echo __METHOD__ . "\n"; |
||||
$this->num++; |
||||
} |
||||
function key(): mixed { |
||||
return $this->num; |
||||
} |
||||
} |
||||
|
||||
class c implements IteratorAggregate { |
||||
|
||||
public $max = 4; |
||||
|
||||
function getIterator(): Traversable { |
||||
echo __METHOD__ . "\n"; |
||||
return new c_iter($this); |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
$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::getIterator |
||||
c_iter::__construct |
||||
c_iter::rewind |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
continue outer |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
c::getIterator |
||||
c_iter::__construct |
||||
c_iter::rewind |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
double:1:0 |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
continue inner |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
break inner |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
c::getIterator |
||||
c_iter::__construct |
||||
c_iter::rewind |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
double:2:0 |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
continue inner |
||||
c_iter::next |
||||
c_iter::valid = true |
||||
c_iter::current |
||||
break inner |
||||
break outer |
||||
Done |
||||
Loading…
Reference in new issue