3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myIterator implements Iterator { public function __construct() { $this->position = 0; } public function rewind() { var_dump(__METHOD__); $this->position = 0; } public function current() { var_dump(__METHOD__); return $this->position; } public function key() { var_dump(__METHOD__); return $this->position; } public function next() { var_dump(__METHOD__); ++$this->position; } public function valid() { var_dump(__METHOD__); return true; } } $i = new LimitIterator(new myIterator, 0, 3); $i = new CachingIterator($i); $i->rewind(); echo "\n1st iteration\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; $i->next(); echo "\n2nd iteration\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; $i->next(); echo "\n3rd iteration\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; $i->next(); echo "\n4th iteration\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; $i->next(); echo "\n5th iteration\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; $i->next();
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/aWoPk on line 13 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/aWoPk on line 23 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/aWoPk on line 18 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/aWoPk on line 28 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/aWoPk on line 8 Deprecated: Creation of dynamic property myIterator::$position is deprecated in /in/aWoPk on line 5 string(18) "myIterator::rewind" string(17) "myIterator::valid" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" 1st iteration Valid Current key: 0 Current value: 0 string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" 2nd iteration Valid Current key: 1 Current value: 1 string(16) "myIterator::next" 3rd iteration Valid Current key: 2 Current value: 2 4th iteration Not valid Current key: NULL Current value: NULL 5th iteration Not valid Current key: NULL Current value: NULL

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:
42.73 ms | 405 KiB | 8 Q