A workaround that causes global variables globally to fail after multiple include in PHP, global variables
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:
<?PHP$AA = 1;? >
b.php file:
<?phpinclude a.phpfunction 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:
<?php$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/962097.html www.bkjia.com true http://www.bkjia.com/PHPjc/962097.html techarticle Workaround for global variables globally invalidation after multiple include of PHP, global variables Globally This example describes a workaround that causes global variables to fail after multiple include in PHP. Share to ...