3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Test { protected $objects; public function __construct() { $this->objects = new \SplObjectStorage; } public function getObjectState($object) { return $this->objects[$object]; } public function attach($object, $state = 1) { $this->objects->attach($object, $state); } } class Object { } class Object2 { } $test = new Test(); $object = new Object(); $object2 = new Object2(); $test->attach($object, 2); print_r($test->getObjectState($object)); print_r($test->getObjectState($object2));
Output for 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Fatal error: Cannot use 'Object' as class name as it is reserved in /in/LS2j6 on line 22
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
2 Fatal error: Uncaught UnexpectedValueException: Object not found in /in/LS2j6:13 Stack trace: #0 /in/LS2j6(13): SplObjectStorage->offsetGet(Object(Object2)) #1 /in/LS2j6(35): Test->getObjectState(Object(Object2)) #2 {main} thrown in /in/LS2j6 on line 13
Process exited with code 255.
Output for 5.4.1 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
2 Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Object not found' in /in/LS2j6:13 Stack trace: #0 /in/LS2j6(13): SplObjectStorage->offsetGet(Object(Object2)) #1 /in/LS2j6(35): Test->getObjectState(Object(Object2)) #2 {main} thrown in /in/LS2j6 on line 13
Process exited with code 255.

preferences:
190.23 ms | 402 KiB | 227 Q