3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myIterator implements Iterator { private $position = 0; private $array = [ "a", "b", "c" ]; public function __construct() { print(__METHOD__.PHP_EOL); $this->position = 0; } public function current () { print(__METHOD__.PHP_EOL); return $this->array[$this->position]; } public function next () { print(__METHOD__.PHP_EOL); ++$this->position; } public function key () { print(__METHOD__.PHP_EOL); return $this->position; } public function valid () { print(__METHOD__.PHP_EOL); return isset($this->array[$this->position]); } public function rewind () { print(__METHOD__.PHP_EOL); $this->position = 0; } } $obj = new myIterator(); //e1 while($obj->valid()) { $k = $obj->key(); $v = $obj->current(); print_r([$k,$v]); $obj->next(); } //e2 foreach($obj as $k=>$v) { print_r([$k,$v]); }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of myIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/goGiB on line 15 Deprecated: Return type of myIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/goGiB on line 20 Deprecated: Return type of myIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/goGiB on line 25 Deprecated: Return type of myIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/goGiB on line 30 Deprecated: Return type of myIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/goGiB on line 35 myIterator::__construct myIterator::valid myIterator::key myIterator::current Array ( [0] => 0 [1] => a ) myIterator::next myIterator::valid myIterator::key myIterator::current Array ( [0] => 1 [1] => b ) myIterator::next myIterator::valid myIterator::key myIterator::current Array ( [0] => 2 [1] => c ) myIterator::next myIterator::valid myIterator::rewind myIterator::valid myIterator::current myIterator::key Array ( [0] => 0 [1] => a ) myIterator::next myIterator::valid myIterator::current myIterator::key Array ( [0] => 1 [1] => b ) myIterator::next myIterator::valid myIterator::current myIterator::key Array ( [0] => 2 [1] => c ) myIterator::next myIterator::valid

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.97 ms | 405 KiB | 8 Q