Theres I used to, but rather hacked, you can pass the array to stdclass, then serialize it to a string, and then use the string manipulation to change the class name and then unserialize the object:
function ClassCaster($class, $object)
{
return unserialize(preg_replace('/^O:\d+:"[^"]++"/', 'O:' . strlen($class) . ':"' . $class . '"', serialize($object)));
}
class SampleClass
{
public function __wakeup(){ }
}
$array = array();
$SampleClass = ClassCaster("SampleClass",(object)$array);
This is not a good method, but I consider it the only hack.
source
share