Before PHP5, each PHP framework, if you want to implement the automatic loading of classes, is generally a kind of convention to implement a traversal directory, automatically load all the files that meet the Convention rules of the class or function. Of course, PHP5 support is not very good before, and the use of classes is not now frequent. Let's discuss it in detail.
Automatic loading method for PHP classes
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55-56 |
The <?php class Inload {/** * class is automatically loaded and does not need to be called by the developer * * @param string $class class file/Private function AutoLoad ($class) {if (EM) Pty ($class)) {throw new qexception (' Load file does not exist '. $class);} else {require _spring_. ' /_core/springmap.php '; Frame map if (! file_exists ($source [$class] [' file ']) {throw new qexception (' Load file does not exist '. $class); require $source [$class] [' File ']; /** * Register or unregister an automatic class loading method * This method refers to the Zend Framework * * @param string $class provides a class * @param boolean $enabled that automatically loads the service to enable or disable the Service/Private Function registerautoload ($class = ' interpreter ', $enabled = True) {if (!function_exists) (' Spl_autoload_reg Ister ')) {throw new Qexception (' Spl_autoload does not exist for this PHP installation ');} if ($enabled = = True) {Spl_autoload_register (Array ($class , ' autoload ')); else {spl_autoload_unregister (array ($class, ' autoload '));} /** * destructor/Public Function __destruct () {self::registerautoload (' interpreter ', false); |
The above mentioned is the entire content of this article, I hope you can enjoy.