我想懒惰加载类但没有成功
<?PHP class Employee{ function __autoload($class){ require_once($class); } function display(){ $obj = new employeeModel(); $obj->printSomthing(); } }
现在当我做这个
function display(){ require_once('emplpyeeModel.PHP'); $obj = new employeeModel(); $obj->printSomthing(); }
它有效,但我想懒得加载这个类.
稍微改变一下员工:
class Employee { public static function __autoload($class) { //_once is not needed because this is only called once per class anyway,//unless it fails. require $class; } /* Other methods Omitted */ } spl_autoload_register('Employee::__autoload');