3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BadIterator implements Iterator { private $data = [1, 2, 3, 4, 5]; private $pos = 0; public function current() { return $this; } public function key() { return $this->pos; } public function next() { $this->pos++; } public function rewind() { $this->pos = 0; } public function valid() { return $this->pos < count($this->data); } public function __toString() { return (string) $this->data[$this->pos]; } } echo "Direct iteration:\n"; foreach (new BadIterator as $val) { echo "$val\n"; } echo "Caching iteration:\n"; foreach (new CachingIterator(new BadIterator) as $val) { echo "$val\n"; }
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of BadIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/dUgEg on line 8 Deprecated: Return type of BadIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/dUgEg on line 18 Deprecated: Return type of BadIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/dUgEg on line 13 Deprecated: Return type of BadIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/dUgEg on line 28 Deprecated: Return type of BadIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/dUgEg on line 23 Direct iteration: 1 2 3 4 5 Caching iteration: 2 3 4 5 Warning: Undefined array key 5 in /in/dUgEg on line 35

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:
56.01 ms | 403 KiB | 8 Q