Think I need to use reflection to make this 5.3 code work on 5.2 but having issues.
We are on a server that only has PHP 5.2, upgrade is not possible at this time per hosting company but a class we need has issues on 5.2 since the class uses 5.3 syntax.
Here is the code I need help with:
static public function instance($class) {
if (!isset($class::$instance)) {
$class::$instance = new $class();
开发者_StackOverflow $class::$instance->initialize();
MobileHelper::registerDevice($class::$instance);
}
return $class::$instance;
}
I have seen a number of answers on questions that note to use reflection, but they are all basic examples, I don't know enough to convert them into the solution here, but I have tried. Any expert here able to help on this?
Here, same using Reflection.
static public function instance($class) {
$ref = new ReflectionClass($class);
if (!$ref->getStaticPropertyValue('instance')){
$ref->setStaticPropertyValue('instance', new $class());
$obj = $ref->getStaticPropertyValue('instance');
$obj->initialize();
MobileHelper::registerDevice($obj);
}
return $ref->getStaticPropertyValue('instance');
}
精彩评论