php-src/ext/spl/tests/sequence.phpt

138 lines
2.4 KiB
Plaintext
Raw Normal View History

2003-05-01 23:28:28 +00:00
--TEST--
SPL: sequence
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
2003-06-04 20:54:48 +00:00
class c implements spl_iterator {
2003-05-01 23:28:28 +00:00
public $max = 3;
function new_iterator() {
2003-06-01 16:41:53 +00:00
echo __METHOD__ . "\n";
2003-05-01 23:28:28 +00:00
return new c_iter($this);
}
}
2003-06-04 20:54:48 +00:00
class c_iter implements spl_sequence_assoc {
2003-05-01 23:28:28 +00:00
private $obj;
private $num = 0;
function __construct($obj) {
$this->obj = $obj;
}
function rewind() {
2003-06-01 16:41:53 +00:00
echo __METHOD__ . "\n";
2003-05-01 23:28:28 +00:00
$this->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->obj->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 "???";
}
}
}
$t = new c();
$i = $t->new_iterator();
$c_info = array(get_class($t) => array('inheits' => class_parents($t), 'implements' => class_implements($t)),
get_class($i) => array('inheits' => class_parents($i), 'implements' => class_implements($i)));
2003-05-01 23:28:28 +00:00
print_r($c_info);
foreach($i as $w) {
echo "object:$w\n";
}
foreach($i as $v => $w) {
echo "object:$v=>$w\n";
}
print "Done\n";
?>
--EXPECT--
c::new_iterator
Array
(
[c] => Array
(
[inheits] => Array
(
)
[implements] => Array
(
2003-06-04 20:54:48 +00:00
[spl_iterator] => spl_iterator
2003-05-01 23:28:28 +00:00
)
)
[c_iter] => Array
(
[inheits] => Array
(
)
[implements] => Array
(
2003-06-04 20:54:48 +00:00
[spl_sequence_assoc] => spl_sequence_assoc
[spl_forward_assoc] => spl_forward_assoc
[spl_assoc] => spl_assoc
[spl_forward] => spl_forward
[spl_sequence] => spl_sequence
2003-05-01 23:28:28 +00:00
)
)
)
c_iter::rewind
c_iter::has_more
c_iter::current
c_iter::key
object:0
c_iter::next
c_iter::has_more
c_iter::current
c_iter::key
object:1
c_iter::next
c_iter::has_more
c_iter::current
c_iter::key
object:2
c_iter::next
c_iter::has_more
c_iter::rewind
c_iter::has_more
c_iter::current
c_iter::key
object:1st=>0
c_iter::next
c_iter::has_more
c_iter::current
c_iter::key
object:2nd=>1
c_iter::next
c_iter::has_more
c_iter::current
c_iter::key
object:3rd=>2
c_iter::next
c_iter::has_more
Done