--------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 ?>-----------调用类方法------------<?phpclass Loader{ public static function loadClass($class_name) { require_once $class_name . '.php'; }}spl_load_register(array('Loader', 'loadClass'));?>
详细解决方案
_autoload自动加载种文件 和spl_autoload_register函数
热度:151 发布时间:2016-05-05 06:26:30.0
相关解决方案
- WEB-INF 上的jsp文件,用ext tabpanel autoload url如何访问
- Ext.Panel 中 autoLoad 加载页面,不能运行js的有关问题
- spl_autoload_register() 第三个参数是什么意思?该如何解决
- spl_autoload_register()跟_autoload()
- PHP种的自动加载_autoload && spl_autoload_register
- composer install 报错Script @php artisan package:discover --ansi handling the post-autoload-dump event
- composer dump-autoload
- git 拖下laravel 代码后报错 Warning: require(D:\WWW\laravel\bootstrap/../vendor/autoload.php