自动加载:
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');