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; } } class NextLimitingIterator extends LimitIterator { public function next() { $this->valid() && parent::next(); } } $it = new NextLimitingIterator(new myIterator, 0, 3); foreach($it as $key => $value) { var_dump($key, $value); echo "\n"; } var_dump($it->valid()); var_dump($it->valid()); var_dump($it->valid()); var_dump($it->next()); var_dump($it->next()); var_dump($it->next());
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Deprecated: Return type of NextLimitingIterator::next() should either be compatible with LimitIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uW1sp on line 35 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp on line 8 Deprecated: Creation of dynamic property myIterator::$position is deprecated in /in/uW1sp on line 5 string(18) "myIterator::rewind" string(17) "myIterator::valid" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) int(0) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) int(1) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) int(2) string(16) "myIterator::next" bool(false) bool(false) bool(false) NULL NULL NULL
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 NextLimitingIterator::next() should either be compatible with LimitIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uW1sp on line 35 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp on line 8 Deprecated: Creation of dynamic property myIterator::$position is deprecated in /in/uW1sp on line 5 string(18) "myIterator::rewind" string(17) "myIterator::valid" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) int(0) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) int(1) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) int(2) string(16) "myIterator::next" bool(false) bool(false) bool(false) NULL NULL NULL
Output for 8.1.0 - 8.1.28
Deprecated: Return type of NextLimitingIterator::next() should either be compatible with LimitIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/uW1sp on line 35 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp 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/uW1sp on line 8 string(18) "myIterator::rewind" string(17) "myIterator::valid" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) int(0) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) int(1) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) int(2) string(16) "myIterator::next" bool(false) bool(false) bool(false) NULL NULL NULL
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(18) "myIterator::rewind" string(17) "myIterator::valid" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(0) int(0) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(1) int(1) string(16) "myIterator::next" string(17) "myIterator::valid" string(19) "myIterator::current" string(15) "myIterator::key" int(2) int(2) string(16) "myIterator::next" bool(false) bool(false) bool(false) NULL NULL NULL

preferences:
112.95 ms | 403 KiB | 155 Q