3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test implements Iterator { private $ar = [ 1, 2, 3 ]; public function toArray() { return $this->ar; } public function rewind() { reset( $this->ar ); } public function valid() { return !is_null( $this->key() ); } public function key() { return key( $this->ar ); } public function current() { return current( $this->ar ); } public function next() { next( $this->ar ); } } $t = new Test; foreach( $t as $key => $value ) { echo "orig: $key: $value\n"; foreach( $t->toArray() as $copyKey => $copyValue ) { echo " copy: $copyKey: $copyValue\n"; } echo "----\n"; }
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
Deprecated: Return type of Test::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/l96fW on line 24 Deprecated: Return type of Test::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/l96fW on line 28 Deprecated: Return type of Test::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/l96fW on line 20 Deprecated: Return type of Test::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/l96fW on line 16 Deprecated: Return type of Test::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/l96fW on line 12 orig: 0: 1 copy: 0: 1 copy: 1: 2 copy: 2: 3 ---- orig: 1: 2 copy: 0: 1 copy: 1: 2 copy: 2: 3 ---- orig: 2: 3 copy: 0: 1 copy: 1: 2 copy: 2: 3 ----
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
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
orig: 0: 1 copy: 0: 1 copy: 1: 2 copy: 2: 3 ---- orig: 1: 2 copy: 0: 1 copy: 1: 2 copy: 2: 3 ---- orig: 2: 3 copy: 0: 1 copy: 1: 2 copy: 2: 3 ----

preferences:
179.45 ms | 411 KiB | 5 Q