2003-05-01 23:28:28 +00:00
|
|
|
--TEST--
|
|
|
|
SPL: forward
|
|
|
|
--SKIPIF--
|
|
|
|
<?php if (!extension_loaded("spl")) print "skip"; ?>
|
|
|
|
--FILE--
|
|
|
|
<?php
|
2003-06-04 20:54:48 +00:00
|
|
|
class c implements spl_forward_assoc {
|
2003-05-01 23:28:28 +00:00
|
|
|
|
|
|
|
public $max = 3;
|
|
|
|
public $num = 0;
|
|
|
|
|
|
|
|
function current() {
|
2003-06-01 16:41:53 +00:00
|
|
|
echo __METHOD__ . "\n";
|
2003-05-01 23:28:28 +00:00
|
|
|
return $this->num;
|
|
|
|
}
|
|
|
|
function next() {
|
2003-06-01 16:41:53 +00:00
|
|
|
echo __METHOD__ . "\n";
|
2003-05-01 23:28:28 +00:00
|
|
|
$this->num++;
|
|
|
|
}
|
|
|
|
function has_more() {
|
2003-06-01 16:41:53 +00:00
|
|
|
echo __METHOD__ . "\n";
|
2003-05-01 23:28:28 +00:00
|
|
|
return $this->num < $this->max;
|
|
|
|
}
|
|
|
|
function key() {
|
2003-06-01 16:41:53 +00:00
|
|
|
echo __METHOD__ . "\n";
|
2003-05-01 23:28:28 +00:00
|
|
|
switch($this->num) {
|
|
|
|
case 0: return "1st";
|
|
|
|
case 1: return "2nd";
|
|
|
|
case 2: return "3rd";
|
|
|
|
default: return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$i = new c();
|
|
|
|
|
2003-06-17 20:18:10 +00:00
|
|
|
$c_info = array(get_class($i) => array('inheits' => class_parents($i), 'implements' => class_implements($i)));
|
2003-05-01 23:28:28 +00:00
|
|
|
print_r($c_info);
|
2003-06-04 20:54:48 +00:00
|
|
|
$methods = get_class_methods("spl_forward_assoc");
|
2003-05-26 22:06:49 +00:00
|
|
|
sort($methods);
|
|
|
|
print_r($methods);
|
|
|
|
$methods = get_class_methods($i);
|
|
|
|
sort($methods);
|
|
|
|
print_r($methods);
|
|
|
|
|
2003-05-01 23:28:28 +00:00
|
|
|
|
|
|
|
echo "1st try\n";
|
|
|
|
foreach($i as $w) {
|
|
|
|
echo "object:$w\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "2nd try\n";
|
|
|
|
|
|
|
|
foreach($i as $v => $w) {
|
|
|
|
echo "object:$v=>$w\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "3rd try\n";
|
|
|
|
$i->num = 0;
|
|
|
|
|
|
|
|
foreach($i as $v => $w) {
|
|
|
|
echo "object:$v=>$w\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
print "Done\n";
|
|
|
|
?>
|
|
|
|
--EXPECT--
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[c] => Array
|
|
|
|
(
|
|
|
|
[inheits] => Array
|
|
|
|
(
|
|
|
|
)
|
|
|
|
|
|
|
|
[implements] => Array
|
|
|
|
(
|
2003-06-04 20:54:48 +00:00
|
|
|
[spl_forward_assoc] => spl_forward_assoc
|
|
|
|
[spl_assoc] => spl_assoc
|
|
|
|
[spl_forward] => spl_forward
|
2003-05-01 23:28:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
2003-05-26 22:06:49 +00:00
|
|
|
Array
|
|
|
|
(
|
|
|
|
[0] => current
|
|
|
|
[1] => has_more
|
|
|
|
[2] => key
|
|
|
|
[3] => next
|
|
|
|
)
|
|
|
|
Array
|
|
|
|
(
|
|
|
|
[0] => current
|
|
|
|
[1] => has_more
|
|
|
|
[2] => key
|
|
|
|
[3] => next
|
|
|
|
)
|
2003-05-01 23:28:28 +00:00
|
|
|
1st try
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:0
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:1
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:2
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
2nd try
|
|
|
|
c::has_more
|
|
|
|
3rd try
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:1st=>0
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:2nd=>1
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
c::current
|
|
|
|
c::key
|
|
|
|
object:3rd=>2
|
|
|
|
c::next
|
|
|
|
c::has_more
|
|
|
|
Done
|