obtaining instance of a singleton object with variable name
Posted: Wed Jun 14, 2006 11:01 pm
The following works to instantiate a class with a variable name
I want to do something similar, except I want to get an instance of a singleton object. The following code, obviously, throws an error
The way I worked around this follows
However this is incredibly slow because its a user created function. If you know how to do this without a hack id like to hear it.
Code: Select all
$class_name = 'blah';
$newclass = new $class_name();Code: Select all
$class_name = 'blah';
$newclass = $class_name::instance();Code: Select all
$load_driver = create_function('','if(!$retval = '.$driver_name.'::instance()){return false;} return $retval;');