2003-10-23 04:04:48 +08:00
|
|
|
--TEST--
|
|
|
|
ZE2 iterators must be implemented
|
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
|
|
|
echo "1st try\n";
|
|
|
|
|
|
|
|
class c1 {}
|
|
|
|
|
|
|
|
$obj = new c1();
|
|
|
|
|
|
|
|
foreach($obj as $w) {
|
|
|
|
echo "object:$w\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "2nd try\n";
|
|
|
|
|
|
|
|
class c2 {
|
|
|
|
|
|
|
|
public $max = 3;
|
|
|
|
public $num = 0;
|
|
|
|
|
|
|
|
function current() {
|
|
|
|
echo __METHOD__ . "\n";
|
|
|
|
return $this->num;
|
|
|
|
}
|
|
|
|
function next() {
|
|
|
|
echo __METHOD__ . "\n";
|
|
|
|
$this->num++;
|
|
|
|
}
|
2004-03-09 01:33:31 +08:00
|
|
|
function valid() {
|
2003-10-23 04:04:48 +08:00
|
|
|
echo __METHOD__ . "\n";
|
|
|
|
return $this->num < $this->max;
|
|
|
|
}
|
|
|
|
function key() {
|
|
|
|
echo __METHOD__ . "\n";
|
|
|
|
switch($this->num) {
|
|
|
|
case 0: return "1st";
|
|
|
|
case 1: return "2nd";
|
|
|
|
case 2: return "3rd";
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$obj = new c2();
|
|
|
|
|
|
|
|
foreach($obj as $v => $w) {
|
|
|
|
echo "object:$v=>$w\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "Done\n";
|
|
|
|
?>
|
2018-02-19 16:59:41 +08:00
|
|
|
--EXPECT--
|
2003-10-23 04:04:48 +08:00
|
|
|
1st try
|
|
|
|
2nd try
|
|
|
|
object:max=>3
|
|
|
|
object:num=>0
|
|
|
|
Done
|