3v4l.org

run code in 300+ PHP versions simultaneously
<?php class hello { public $props = array(); function __construct() { $this->props = ['hello' => 5, 'props' => ['keyme' => ['test' => 5]]]; } } $data = new hello(); $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data), RecursiveIteratorIterator::SELF_FIRST); echo "Expect to see all keys in ->props here: \n"; foreach($iterator as $k=>$v) { echo $k . "\n"; } echo "Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html \n"; class RecursiveArray extends ArrayIterator implements RecursiveIterator { function hasChildren() { return is_array($this->current()); } function getChildren() { if ($this->current() instanceof self) { return $this->current(); } if (empty($this->ref)) { $this->ref = new ReflectionClass($this); } return $this->ref->newInstance($this->current()); } private $ref; } echo "Expect to see all keys in ->props here: \n"; $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($data), RecursiveIteratorIterator::SELF_FIRST); echo "Expect to see all keys in ->props here: \n"; foreach($iterator as $k=>$v) { echo $k . "\n"; }
Output for 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Expect to see all keys in ->props here: props hello props keyme test Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html Deprecated: Return type of RecursiveArray::hasChildren() should either be compatible with RecursiveIterator::hasChildren(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IBrNH on line 26 Deprecated: Return type of RecursiveArray::getChildren() should either be compatible with RecursiveIterator::getChildren(): ?RecursiveIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IBrNH on line 31 Expect to see all keys in ->props here: Expect to see all keys in ->props here: props hello props keyme test
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 Expect to see all keys in ->props here: props hello props keyme test Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html Deprecated: Return type of RecursiveArray::hasChildren() should either be compatible with RecursiveIterator::hasChildren(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IBrNH on line 26 Deprecated: Return type of RecursiveArray::getChildren() should either be compatible with RecursiveIterator::getChildren(): ?RecursiveIterator, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/IBrNH on line 31 Expect to see all keys in ->props here: Expect to see all keys in ->props here: props hello props keyme test
Output for 5.6.0 - 5.6.26, 7.1.20 - 7.1.33, 7.2.2 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
Expect to see all keys in ->props here: props hello props keyme test Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html Expect to see all keys in ->props here: Expect to see all keys in ->props here: props hello props keyme test
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.7, 7.2.0 - 7.2.1
Expect to see all keys in ->props here: props Reimplemented RecursiveArrayIterator from source code here: http://fossies.org/dox/php-7.0.11-src/recursivearrayiterator_8inc_source.html Expect to see all keys in ->props here: Expect to see all keys in ->props here: props

preferences:
173.14 ms | 402 KiB | 229 Q