PHP 使用__autoload()方法避免频繁使用require()函数。

来源:互联网 发布:mysql开启远程连接 编辑:程序博客网 时间:2024/06/14 16:11
./myClass.php<?phpclass myClass {    public function __construct() {        echo "myClass init'ed successfuly!!!";    }}?>./index.php<?php// we've writen this code where we needfunction __autoload($classname) {    $filename = "./". $classname .".php";    include_once($filename);}// we've called a class ***$obj = new myClass();?>

使用该__autoload()方法就可以避免调用其他类时,频繁使用require函数。

原创粉丝点击