3v4l.org

run code in 300+ PHP versions simultaneously
<?php class StandardClass extends StdClass implements IteratorAggregate{ function getIterator(){ $d = (array)$this; ksort($d); return new ArrayIterator($d); } function __debugInfo(){ $d = (array)$this; ksort($d); return $d; } } $x = new StandardClass; $x->c = 10; $x->a = 10; $x->b = 10; var_dump($x); foreach($x as $k => $v){ echo $k . '=>' . $v . "\n"; }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Deprecated: Return type of StandardClass::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/J24Xl on line 4 object(StandardClass)#1 (3) { ["a"]=> int(10) ["b"]=> int(10) ["c"]=> int(10) } a=>10 b=>10 c=>10
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
object(StandardClass)#1 (3) { ["a"]=> int(10) ["b"]=> int(10) ["c"]=> int(10) } a=>10 b=>10 c=>10
Output for 5.5.0 - 5.5.38
object(StandardClass)#1 (3) { ["c"]=> int(10) ["a"]=> int(10) ["b"]=> int(10) } a=>10 b=>10 c=>10

preferences:
216.67 ms | 401 KiB | 332 Q