__autoload自动加载类文件 和spl_autoload_register函数
--------clsdemo.php文件-------- <?php class clsdemo { public function show(){ echo "test"; } } ?> ---------index.php文件--------- //不需要include require单独引用 php5函数 会在IO文件时有一定的性能消耗 <?php function __autoload($class_name) { require_once $class_name . '.php'; } $test = new clsdemo(); $test->show(); //显示是test ?> ---------spl.php文件----------- <?php function loader($class_name) { require_once $class_name . '.php'; } spl_load_register('loader'); //自动加载的时候不调用__autoload()而调用自己的函数或类方法 $test = new clsdemo(); $test->show(); //显示是test ?> -----------调用类方法------------ <?php class Loader { public static function loadClass($class_name) { require_once $class_name . '.php'; } } spl_load_register(array('Loader', 'loadClass')); ?>
相关推荐
聪聪李 2020-09-10
WasteLand 2020-09-15
wwwsurfphpseocom 2020-10-28
zyyjay 2020-11-09
xuebingnan 2020-11-05
samtrue 2020-11-22
stefan0 2020-11-22
yifangs 2020-10-13
songshijiazuaa 2020-09-24
hebiwtc 2020-09-18
天步 2020-09-17
83911535 2020-11-13
whatsyourname 2020-11-13
zhouyuqi 2020-11-10
Noneyes 2020-11-10
mathchao 2020-10-28
王志龙 2020-10-28