psr-4

自动加载:

 1 <?php
 2 
 3 function autoload($className)
 4 {
 5     $className = ltrim($className, '\\');
 6     $fileName  = '';
 7     $namespace = '';
 8     if ($lastNsPos = strrpos($className, '\\')) {
 9         $namespace = substr($className, 0, $lastNsPos);
10         $className = substr($className, $lastNsPos + 1);
11         $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
12     }
13     $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
14 
15     require $fileName;
16 }
17 spl_autoload_register('autoload');

 

posted @ 2016-04-09 16:56  lpfuture  阅读(222)  评论(0编辑  收藏  举报