3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
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.1.10
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.3.18 - 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.