PHP __autoload()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP __autoload()相关的知识,希望对你有一定的参考价值。

/*
Autoload for php classes with a simple convention so you don't have to include manually files.
The convention is as follow: '_' gets converted into '/' and the strings before and after '_' become
directories or files.
For example Process_Shell class is located under directory Process and the file name that contains
the class Process_Shell is called Shell.php. The classname is Process_Process and is located into
Process/Shell.php.

*/

function __autoload($class){
    $elems = explode('_',$class);
    $path = implode('/',$elems);
    require_once($path . '.' . 'php');
}

以上是关于PHP __autoload()的主要内容,如果未能解决你的问题,请参考以下文章