How to avoid repeated references in php

Source: Internet
Author: User

As you know, in C, we can use # define to define a MACRO name and check whether the MACRO name is defined to determine whether the header file needs to be referenced. The same problem also exists in PHP. For example, A references B, C, and B to C. If no action is taken, C will be referenced twice. This may cause some strange problems.

I define a global variable and check whether the variable is defined to solve this problem. The solution is very simple, similar to C.
I recommend that you use the naming rules of [user_packages] [headfilename] for this global variable. It may be better.

If (! Empty ($ GLOBALS [bookstils] [GLOBALDEFINE]) return;
$ GLOBALS [bookstils] [GLOBALDEFINE] = true;

Class bookstils {...
};

In addition, use require_once "headfiles. php" in the main program to avoid repeated references.
This method has been applied in our development team, and the effect is quite good. You may wish to do the same.

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.