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 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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
Output for 8.1.0 - 8.1.27
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 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
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
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
Output for 5.6.40
Parse error: syntax error, unexpected '?' in /in/IrAWU on line 41
Process exited with code 255.

preferences:
139.94 ms | 401 KiB | 153 Q