The thought course of PHP object-oriented oop-class auto-loading

Source: Internet
Author: User
At the very beginning, when we use one or more classes, it is generally necessary to use the require or include function to introduce the class before it can be used;

But when there are so many classes in a project, we have to introduce them all in one file when we use them, so

On the one hand is more cumbersome, not high efficiency. On the other hand, when we delete some of these classes, we are going to delete the corresponding require or include

statement, error prone;

To avoid the above situation, we used the PHP Magic function __autoload () to avoid the introduction of the class in the above cases,

But the new problems have arisen again. When one of our projects uses multiple frames, if the __autoload () function is used in each frame,

Then there will be a fatal error with the function repeating definition;

To solve this problem, the Sql_autoload_register () function appears in php5.3 and later versions, using this function we can

Registering a custom AutoLoad function solves the problem of duplicate function definition;

So many times now we are using the Sql_autoload_register () function to implement automatic loading of classes;

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the PHP object-oriented oop-class automatic loading of the thought process, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.