PHP automatic loading autoload mechanism is very important, here do 2 small exercises original articles, reproduced please note: HTTP://WWW.CNBLOGS.COM/PHPGCS file structure as follows, 2 ways to implement automatic loading 1, custom Function 2,spl_autoload_ Register () liuyuan@ebuinfo:/var/www/phpgcs/php_autoload$ LL./*-rw-rw-r--1 Liuyuan Liuyuan 11:39./func_autol oad.php-rw-rw-r--1 Liuyuan Liuyuan 906 Feb 11:28./spl_autoload.php./include:total 16drwxrwxr-x 2 Liuyuan Liuyuan 409 6 11:42./drwxrwxr-x 3 Liuyuan liuyuan 4096 Feb 19 11:43.. /-rw-rw-r--1 Liuyuan Liuyuan 142 Feb 11:42 aclass.php-rw-rw-r--1 Liuyuan Liuyuan 143 Feb 11:42 bClass.php First look at the custom function mode: '); 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/'. $className. 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 > operation results are as follows: + View Code the second way: '); Spl_autoload_register (Array (' Myloader ', ' autoload ')); The/** *__autoload method fails after spl_autoload_register because the AUTOLOAD_FUNC function pointer has pointed to the Spl_autoload method * You can add the _autoload method to Autol by using the following method Oad_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;? >
http://www.bkjia.com/PHPjc/735880.html www.bkjia.com true http://www.bkjia.com/PHPjc/735880.html techarticle PHP Automatic loading autoload mechanism is very important, here do 2 small exercises original articles, reproduced please note: HTTP://WWW.CNBLOGS.COM/PHPGCS file structure as follows, 2 ways to achieve automatic loading 1, ...