To restore the state of an object which has been persisted, I'd like to create an empty instance of the class, without calling its constructor, to later set the properties with Reflection.
The only way I found, which is the way Doctrine does, is to create a fake serialization of the object, and to unserialize()
it:
function prototype($class)
{
$serialized = sprintf('O:%u:"%s":0:{}', strlen($class), $class);
return unserialize($serialized);
}
Is there another, less hacky way, to do that?
I was expecting to find such a way in Reflection, but I did not.
Update: ReflectionClass::newInstanceWithoutConstructor is available since PHP 5.4!