3v4l.org

run code in 300+ PHP versions simultaneously
<?php $INDENT = 0; trait ShowMethodCalls { private function show($method) { global $INDENT; printf("%s%s::%s\n", str_repeat("> ", $INDENT++), __CLASS__, $method); $return = parent::$method(); $INDENT--; return $return; } public function accept() { return $this->show(__FUNCTION__); } public function current() { return $this->show(__FUNCTION__); } public function key() { return $this->show(__FUNCTION__); } public function next() { return $this->show(__FUNCTION__); } public function rewind() { return $this->show(__FUNCTION__); } public function valid() { return $this->show(__FUNCTION__); } } class TestFilterIterator extends FilterIterator { public function accept() { echo __FUNCTION__, PHP_EOL; return (bool)parent::current(); } } class ArrayIterator_ extends ArrayIterator { use ShowMethodCalls; } class TestFilterIterator_ extends TestFilterIterator { use ShowMethodCalls; } class LimitIterator_ extends LimitIterator { use ShowMethodCalls; } $iterator = new ArrayIterator_(array('0', 'a', '0', 'b', '0', 'c', '0', 'd')); $iterator = new TestFilterIterator_($iterator); $iterator = new LimitIterator_($iterator, 0, 2); foreach ($iterator as $k => $v) { var_dump([$k, $v]); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Deprecated: Return type of TestFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 23 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with ArrayIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with ArrayIterator::key(): string|int|null, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with ArrayIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with ArrayIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with ArrayIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with IteratorIterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with FilterIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with FilterIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with IteratorIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with IteratorIterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with LimitIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with LimitIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with LimitIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 LimitIterator_::rewind > TestFilterIterator_::rewind > > ArrayIterator_::rewind > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(1) [1]=> string(1) "a" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(3) [1]=> string(1) "b" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept LimitIterator_::valid
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 TestFilterIterator::accept() should either be compatible with FilterIterator::accept(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 23 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with ArrayIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with ArrayIterator::key(): string|int|null, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with ArrayIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with ArrayIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with ArrayIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with IteratorIterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with FilterIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with FilterIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with IteratorIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 Deprecated: Return type of ShowMethodCalls::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 14 Deprecated: Return type of ShowMethodCalls::key() should either be compatible with IteratorIterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 15 Deprecated: Return type of ShowMethodCalls::next() should either be compatible with LimitIterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 16 Deprecated: Return type of ShowMethodCalls::rewind() should either be compatible with LimitIterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 17 Deprecated: Return type of ShowMethodCalls::valid() should either be compatible with LimitIterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/U61Ii on line 18 LimitIterator_::rewind > TestFilterIterator_::rewind > > ArrayIterator_::rewind > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(1) [1]=> string(1) "a" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(3) [1]=> string(1) "b" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept LimitIterator_::valid
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
LimitIterator_::rewind > TestFilterIterator_::rewind > > ArrayIterator_::rewind > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(1) [1]=> string(1) "a" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > TestFilterIterator_::valid > TestFilterIterator_::current > TestFilterIterator_::key LimitIterator_::valid LimitIterator_::current LimitIterator_::key array(2) { [0]=> int(3) [1]=> string(1) "b" } LimitIterator_::next > TestFilterIterator_::next > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept > > ArrayIterator_::next > > ArrayIterator_::valid > > ArrayIterator_::current > > ArrayIterator_::key > > TestFilterIterator_::accept accept LimitIterator_::valid

preferences:
162.9 ms | 405 KiB | 168 Q