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()的主要内容,如果未能解决你的问题,请参考以下文章

PHP __autoload助手类

PHP __autoload()

在 php __autoload() 中将 CamelCase 转换为 under_score_case

php __autoload 在有命名空间的时候失效(使用的局限性)

在 Laravel 中配置 Autoloader.php [重复]

详解spl_autoload_register() 与 __autoload