Workaround for global variables globally failure due to PHP multiple include
This article mainly introduces the solution of global variable's failure after multiple include of PHP, the example analyzes the principle and solution of $globals failure, and has certain reference value, the need of friends can refer to
This example describes a workaround that causes global variables to fail after multiple include in PHP. Share to everyone for your reference. The specific analysis is as follows:
In multiple files, the file is followed by an include, but the function in the last file cannot refer to the global variable after using global. For example:
a.php file:
?
b.php file:
?
1 2 3 4 5 6 7 |
Include a.php Function Show () { Global $AA; Var_dump ($AA); } ?> |
Display: null;
This failure is caused by a variety of reasons. An effective way is if you decide to use a variable as a global variable for multiple files, then using the $globals array is always valid. For example, the a.php in the above example:
?
1 2 3 |
$GLOBALS [' AA '] = 1; ?> |
This variable can then be referenced in the functions and methods of multiple files.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/962406.html www.bkjia.com true http://www.bkjia.com/PHPjc/962406.html techarticle workaround for global variables globally invalidation after multiple include in PHP this article mainly introduces the solution of the global variable's invalidation after PHP multiple include, and the example analyzes the $globals ...