????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.25 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 nested iteratorAggregates
--FILE--
<?php
class EnglishMealIterator implements Iterator {
private $pos=0;
private $myContent=array("breakfast", "dinner", "tea");
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;
}
}
class A1 implements IteratorAggregate {
function getIterator() {
return new EnglishMealIterator;
}
}
class A2 implements IteratorAggregate {
function getIterator() {
return new A1;
}
}
class A3 implements IteratorAggregate {
function getIterator() {
return new A2;
}
}
echo "\n-----( A1: )-----\n";
foreach (new A1 as $k=>$v) {
echo "$k => $v\n";
}
echo "\n-----( A2: )-----\n";
foreach (new A2 as $k=>$v) {
echo "$k => $v\n";
}
echo "\n-----( A3: )-----\n";
foreach (new A3 as $k=>$v) {
echo "$k => $v\n";
}
?>
===DONE===
--EXPECTF--
-----( A1: )-----
--> EnglishMealIterator::rewind (0)
--> EnglishMealIterator::valid (0)
--> EnglishMealIterator::current (0)
--> EnglishMealIterator::key (0)
meal 0 => breakfast
--> EnglishMealIterator::next (0)
--> EnglishMealIterator::valid (1)
--> EnglishMealIterator::current (1)
--> EnglishMealIterator::key (1)
meal 1 => dinner
--> EnglishMealIterator::next (1)
--> EnglishMealIterator::valid (2)
--> EnglishMealIterator::current (2)
--> EnglishMealIterator::key (2)
meal 2 => tea
--> EnglishMealIterator::next (2)
--> EnglishMealIterator::valid (3)
-----( A2: )-----
--> EnglishMealIterator::rewind (0)
--> EnglishMealIterator::valid (0)
--> EnglishMealIterator::current (0)
--> EnglishMealIterator::key (0)
meal 0 => breakfast
--> EnglishMealIterator::next (0)
--> EnglishMealIterator::valid (1)
--> EnglishMealIterator::current (1)
--> EnglishMealIterator::key (1)
meal 1 => dinner
--> EnglishMealIterator::next (1)
--> EnglishMealIterator::valid (2)
--> EnglishMealIterator::current (2)
--> EnglishMealIterator::key (2)
meal 2 => tea
--> EnglishMealIterator::next (2)
--> EnglishMealIterator::valid (3)
-----( A3: )-----
--> EnglishMealIterator::rewind (0)
--> EnglishMealIterator::valid (0)
--> EnglishMealIterator::current (0)
--> EnglishMealIterator::key (0)
meal 0 => breakfast
--> EnglishMealIterator::next (0)
--> EnglishMealIterator::valid (1)
--> EnglishMealIterator::current (1)
--> EnglishMealIterator::key (1)
meal 1 => dinner
--> EnglishMealIterator::next (1)
--> EnglishMealIterator::valid (2)
--> EnglishMealIterator::current (2)
--> EnglishMealIterator::key (2)
meal 2 => tea
--> EnglishMealIterator::next (2)
--> EnglishMealIterator::valid (3)
===DONE===