Use the _ autoload () function to automatically load classes

Source: Internet
Author: User
However, PHP is not an object-oriented language, but we must rely on it and always prepare this idea. Every time you use a class, you need to include the class file, which is very troublesome. it seems that "object" is not so easy.

Although PHP is not an object-oriented language, we must rely on it and always prepare this idea. Every time a class is used, it is very troublesome to include the class file. it seems that "object" is not so easy to be new. Now, the main character of today is to help us solve this problem. it is the _ autoload () function.

This function is a special function in php. it will be automatically called when trying to use a class that has not been defined, so that we can make a fuss about it, this is to write a code containing a class file. the usage is as follows:

Function _ autoload ($ class_name)
{
If (file_exists $ class_name. '. class. php '))
{
Require_once ($ class_name. '. class. php ');
}
}

In fact, this is so simple. we can write this function in the global configuration file to use the class at will. Note that the class file name must be consistent with the storage directory.

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.