Looking for a better method to impliment the following...
Posted: Tue Apr 25, 2006 5:57 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hey everyone. Shown below is a factory method I have in one of my classes. Each class that is getting dynamically loaded has a getInstance() method. One workaround I found was to use the eval() function. I have found however that the eval() function seems to be extremely slow. Can anyone provide any thoughts idea's on implimenting what I am doing without the use of the eval function?Code: Select all
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');
}feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]