|
| I've a feeling you can simply say:
$class = $type::getInstance();
I have a factory method, thanks to Matt Zandstra and his excellent
articles on patterns at www.zend.com, which, somewhat truncated, is:
$classname = "app_command_$cmd";
if ( class_exists( $classname) ) {
$cmd_class = new ReflectionClass($classname);
if ( $cmd_class->isSubClassOf( self::$base_cmd ) ) {
return $cmd_class->newInstance();
}
}
in which a call the variable works fine without any eval.
On Tue, 25 Apr 2006 08:29:54 -0400, "Shaun" <shaun.bramley@rogers.com>
wrote:
>Hey folks. Shown below is a fatory method I have in one of my classes. One
>of the things that I have noticed is a considerable drop in speed with the
>use of the eval() function call. Can anyone point out a better method for
>trying to do what I want to do? Ideally I would love to get rid of the eval
>( I have never been fond of using function calls like this)
>
>
>
>
> public static function getDAO($type) {
> if (include_once('DAO/' . $type . '.php')) {
> $type = $type . 'DAO';
> if (class_exists($type)) {
> try {
> $class = null;
> $eval = '$class = ' . $type . '::getInstance();';
> eval($eval);
> if ($class instanceof DA ) {
> return $class;
> }
> } catch (Exception $error) {
> return PEAR::raiseError($error->getMessage());
> }
> }
> return PEAR::raiseError('Class: ' . $type . ' coult not be found.');
> }
> return PEAR::raiseError('File not found: ' . $type . '.php');
> }
>
|
|