This article mainly introduces the solution to global failure of global variables caused by multiple php include operations. The example analyzes the principle and solution of $ GLOBALS failure, which has some reference value, for more information, see
This article mainly introduces the solution to global failure of global variables caused by multiple php include operations. The example analyzes the principle and solution of $ GLOBALS failure, which has some reference value, for more information, see
This article describes how to resolve global failure caused by multiple php include operations. Share it with you for your reference. The specific analysis is as follows:
In multiple files, the file is included one by one, but the functions in the last file use global, but the global variables cannot be referenced. For example:
A. php file:
<? Php $ aa = 1;?>
B. php file:
<? Phpinclude a. phpfunction show () {global $ aa; var_dump ($ aa) ;}?>
Display: null;
This failure is caused by multiple reasons. An effective method is to use the $ GLOBALS array if you decide to treat a variable as a global variable of multiple files. For example, in the example above, a. php:
<? Php $ GLOBALS ['aa'] = 1;?>
Then you can reference this variable in functions and methods of multiple files.
I hope this article will help you with php programming.