????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.55 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/self/root/home/b8009/php-5.6.22/tests/lang/ |
Upload File : |
--TEST--
foreach with Iterator.
--FILE--
<?php
class MealIterator implements Iterator {
private $pos=0;
private $myContent=array("breakfast", "lunch", "dinner");
public function valid() {
global $indent;
echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
return $this->pos<3;
}
public function next() {
global $indent;
echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
return $this->myContent[$this->pos++];
}
public function rewind() {
global $indent;
echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
$this->pos=0;
}
public function current() {
global $indent;
echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
return $this->myContent[$this->pos];
}
public function key() {
global $indent;
echo "$indent--> " . __METHOD__ . " ($this->pos)\n";
return "meal " . $this->pos;
}
}
$f = new MealIterator;
var_dump($f);
echo "-----( Simple iteration: )-----\n";
foreach ($f as $k=>$v) {
echo "$k => $v\n";
}
$f->rewind();
$indent = " ";
echo "\n\n\n-----( Nested iteration: )-----\n";
$count=1;
foreach ($f as $k=>$v) {
echo "\nTop level " . $count++ . ": \n";
echo "$k => $v\n";
$indent = " ";
foreach ($f as $k=>$v) {
echo " $k => $v\n";
}
$indent = " ";
}
?>
===DONE===
--EXPECTF--
object(MealIterator)#%d (2) {
["pos":"MealIterator":private]=>
int(0)
["myContent":"MealIterator":private]=>
array(3) {
[0]=>
string(9) "breakfast"
[1]=>
string(5) "lunch"
[2]=>
string(6) "dinner"
}
}
-----( Simple iteration: )-----
--> MealIterator::rewind (0)
--> MealIterator::valid (0)
--> MealIterator::current (0)
--> MealIterator::key (0)
meal 0 => breakfast
--> MealIterator::next (0)
--> MealIterator::valid (1)
--> MealIterator::current (1)
--> MealIterator::key (1)
meal 1 => lunch
--> MealIterator::next (1)
--> MealIterator::valid (2)
--> MealIterator::current (2)
--> MealIterator::key (2)
meal 2 => dinner
--> MealIterator::next (2)
--> MealIterator::valid (3)
--> MealIterator::rewind (3)
-----( Nested iteration: )-----
--> MealIterator::rewind (0)
--> MealIterator::valid (0)
--> MealIterator::current (0)
--> MealIterator::key (0)
Top level 1:
meal 0 => breakfast
--> MealIterator::rewind (0)
--> MealIterator::valid (0)
--> MealIterator::current (0)
--> MealIterator::key (0)
meal 0 => breakfast
--> MealIterator::next (0)
--> MealIterator::valid (1)
--> MealIterator::current (1)
--> MealIterator::key (1)
meal 1 => lunch
--> MealIterator::next (1)
--> MealIterator::valid (2)
--> MealIterator::current (2)
--> MealIterator::key (2)
meal 2 => dinner
--> MealIterator::next (2)
--> MealIterator::valid (3)
--> MealIterator::next (3)
Notice: Undefined offset: 3 in %s on line %d
--> MealIterator::valid (4)
===DONE===