Methods for automatic loading of PHP classes

Source: Internet
Author: User
Tags autoload php class php framework require zend framework

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.