<?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));
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.
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.