3v4l.org

run code in 300+ PHP versions simultaneously
<?php class InfiniteLoggingIterator implements Iterator { public function __construct() { $this->position = 0; } public function rewind() { echo __METHOD__, PHP_EOL; $this->position = 0; } public function current() { echo __METHOD__, PHP_EOL; return $this->position; } public function key() { echo __METHOD__, PHP_EOL; return $this->position; } public function next() { echo __METHOD__, PHP_EOL; ++$this->position; } public function valid() { echo __METHOD__, PHP_EOL; return true; } } $i = new LimitIterator(new InfiniteLoggingIterator, 0, 2); echo "Rewinding outer iterator\n"; $i->rewind(); echo "\nGetting 1st value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 2nd value\n"; $i->next(); echo "\nGetting 2nd (and last) value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 3rd value\n"; $i->next(); echo "\nGetting 3rd value (beyond limit)\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 4th value!\n"; $i->next();
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of InfiniteLoggingIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IrAWU on line 13 Deprecated: Return type of InfiniteLoggingIterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IrAWU on line 23 Deprecated: Return type of InfiniteLoggingIterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IrAWU on line 18 Deprecated: Return type of InfiniteLoggingIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IrAWU on line 28 Deprecated: Return type of InfiniteLoggingIterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IrAWU on line 8 Deprecated: Creation of dynamic property InfiniteLoggingIterator::$position is deprecated in /in/IrAWU on line 5 Rewinding outer iterator InfiniteLoggingIterator::rewind InfiniteLoggingIterator::valid InfiniteLoggingIterator::valid InfiniteLoggingIterator::current InfiniteLoggingIterator::key Getting 1st value Valid Current key: 0 Current value: 0 Proceeding to 2nd value InfiniteLoggingIterator::next InfiniteLoggingIterator::valid InfiniteLoggingIterator::current InfiniteLoggingIterator::key Getting 2nd (and last) value Valid Current key: 1 Current value: 1 Proceeding to 3rd value InfiniteLoggingIterator::next Getting 3rd value (beyond limit) Not valid Current key: NULL Current value: NULL Proceeding to 4th value! InfiniteLoggingIterator::next

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