The example of this article describes the solution to the global variable globally failure with PHP multiple include. Share to everyone for your reference. The specific analysis is as follows:
In multiple files, files are one-by-one include, but the function in the last file cannot reference global variables after using global. For example:
a.php file:
b.php file:
<?php
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 treat a variable as a global variable for multiple files, then using the $globals array is always valid. For example, the a.php in the previous example:
<?php
$GLOBALS [' AA '] = 1;
? >
You can then refer to the variable in multiple file functions and methods.
I hope this article will help you with your PHP program design.