PHP automatic loading autoload mechanism is very important, here do 2 small exercises original article, reprint Please note: http://www.cnblogs.com/phpgcs file structure is as follows, 2 ways to achieve automatic loading 1, custom function 2, spl_autoload_register () liuyuan @ ebuinfo:/var/www/phpgcs/php_autoload $ ll. /*-rw-r -- 1 liuyuan 800 Feb 19 11: 39. /func_autoload.php-rw-rw-r -- 1 liuyuan 906 Feb 19. /spl_autoload.php. /include: total 16drwxrwxr-x 2 liuyuan 4096 Feb 19 11: 42. /drwxrwxr-x 3 liuyuan 4096 Feb 19 .. /-rw-r -- 1 liuyuan 142 Feb 19 11: 42 aClass. php-rw-r -- 1 liuyuan 143 Feb 19 11: 42 bClass. php first looks at the User-Defined Function Method: <? Php define ('eol ', (PHP_SAPI = 'cli ')? PHP_EOL: '</br>'); print_r (get_included_files (); echo EOL; print get_include_path (); echo EOL; // set_include_path (get_include_path (). PATH_SEPARATOR. '/var/www/ly_php/php_spl/include/'); // set_include_path (dirname (_ FILE __). '/include'); // set_include_path (dirname (_ FILE __). '/include/'); function _ autoload ($ className) {$ filename = '. /include /'. $ className. '. php '; // $ filename = '. /include /'. $ classN Ame. '. php '; // $ filename ='/var/www/ly_php/php_spl/include /'. $ className. '. php '; if (file_exists ($ filename) {include_once $ filename;} else {exit ('no file') ;}}$ a = new aClass (); $ B = new bClass (); print_r (get_included_files ();?> The running result is as follows: + View Code Method 2: <? Php class myLoader {public static function autoload ($ className) {$ filename = '. /include /'. $ className. '. php '; if (file_exists ($ filename) {include_once $ filename;} else {exit ('no file') ;}} define ('eol ', (PHP_SAPI = 'cli ')? PHP_EOL: '<br/>'); spl_autoload_register (array ('myloader ', 'autoload');/*** _ autoload method will expire after spl_autoload_register, because the autoload_func function pointer has pointed to the spl_autoload Method *, you can use the following method to add the _ autoload method to the autoload_functions list * // spl_autoload_register ('_ autoload '); error_reporting (E_ALL ^ E_NOTICE ^ E_WARNING ^ E_ERROR); error_reporting (E_NOTICE | E_WARNING); $ a = new aClass (); print_r (get_included_files ()); Echo EOL; $ B = new bClass (); echo EOL;?>