They say that eval() is evil. I want to avoid the use of the eval() line using proper PHP5 functionality. Given a class name in a static class method, how do I make it return a real object?
class Model {
public static function loadModel($sModelPath) {
if (!(strpos(' ' . $sModelPath, '/')>0)) {
$sModelPath .= '/' . $sModelPath;
}
$sModelName = str_replace('/','_',$sModelPath);
// P is a global var for physical path of the website
require_once(P . '_models/' . $sModelPath . '.php');
eval("\$oObject = new $sModelName" . '();');
return $oObject;
}
}