PHP 5 __autoload 函数

WBOY
Release: 2016-06-23 14:32:40
Original
729 people have browsed it

在 PHP 5 中。可以定义一个 __autoload 函数,来省去在每个php文件头上写一个个长长的包含文件列表

 

注意:

在 __autoload 函数中抛出的异常不能被 catch 语句块捕获并导致致命错误。

 

function __autoload($class_name) {

   require_once $class_name . '.php';

}

 

$obj  = new MyClass1();

$obj2 = new MyClass2();

?>

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