Home > Backend Development > PHP Tutorial > How to avoid repeated references in php_PHP tutorial

How to avoid repeated references in php_PHP tutorial

WBOY
Release: 2016-07-13 17:25:17
Original
1122 people have browsed it

As we all know, in C language, we can use #define a MACRO name and determine whether the header file needs to be referenced by checking whether the MACRO name is defined. There is the same problem in PHP, for example: A refers to B, C, B refers to C. If no measures are taken, C will be quoted twice. This may cause some strange problems.

I solved this problem by defining a global variable and checking whether the variable is defined. The method is very simple, similar to C.
For this global variable, I recommend using the naming rule of [user_packages] [headfilename]. Maybe this would be better.

if (!empty($GLOBALS[BOOKSTALLS][GLOBALDEFINE])) return;
$GLOBALS[BOOKSTALLS][GLOBALDEFINE] = true;

class bookstalls {...
};

In addition, try to 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 might as well do the same.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532080.htmlTechArticleAs we all know, in C language, we can use #define a MACRO name by checking whether the MACRO name is defined Come and decide whether the header file needs to be referenced. I have the same problem in PHP...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template