PHP 使用__autoload()方法避免频繁使用require()函数。
2017-07-03 14:50
495 查看
./myClass.php <?php class myClass { public function __construct() { echo "myClass init'ed successfuly!!!"; } } ?> ./index.php <?php // we've writen this code where we need function __autoload($classname) { $filename = "./". $classname .".php"; include_once($filename); } // we've called a class *** $obj = new myClass(); ?>
_autoload()是php中的一个魔术方法,在代码中当调用不存在的类时会自动调用该方法。
使用该__autoload()方法就可以避免调用其他类时,频繁使用require函数。
相关文章推荐
- PHP __autoload()函数(类文件自动加载规则)的使用方法
- PHP伪静态页面函数附使用方法
- 通知php使用自定义的session处理函数来操作session,而不使用php预置的方法
- php __autoload() 函数的使用
- 如何避免使用php的require_once
- PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
- 【ZZ】一些在php中使用header函数设置http头的示例方法
- PHP中以SOCKET方式发送HTTP请求的函数及使用方法
- 【转】PHP 使用header函数设置HTTP头的示例方法 表头
- php park、unpark、ord 函数使用方法(二进制流接口应用实例)
- php中 iconv 函数使用方法
- PHP 长文章分页函数 带使用方法,不会分割段落,翻页在底部
- PHP长文章分页函数,带使用方法,不会分割段落,翻页在底部
- PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
- php中ob(Output Buffer 输出缓冲)函数使用方法
- PHP长文章分页函数,带使用方法,不会分割段落,翻页在底部
- PHP中内部函数使用方法
- PHP数组函数使用方法详解
- PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法
- PHP表单验证的3个函数ISSET()、empty()、is_numeric()的使用方法