Home > Backend Development > PHP Tutorial > php自动加载实现

php自动加载实现

WBOY
Release: 2016-06-20 12:49:06
Original
891 people have browsed it

class Courier{public $name;public function __construct($name){$this->name=$name;}}
Copy after login
自动加载的实现    public function __autoload($calssname){   include strtolower($classname).'.'.'class.php';    }        $a= new Courier('qq');
Copy after login

上面两个文件一个是在 Couerier.class.php文件,里一个是在 qq.php.文件中。

可见当找不到类的时候会自动加载auto load 函数

strtolower  //所有字符串转化为小写
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template