For some global and GLOBALS problems in php, first take a simple example $ a = 'scpng'; functiontest () {global $ a; unset ($ a);} test (); var_dump ($ a); functiontest1 () {global and GLOBALS problems in un php
First, let's look at a simple example.
$a = 'scnjl';function test() {global $a;unset($a);}test();var_dump($a);function test1() {unset($GLOBALS['a']);}test1();var_dump($a);
? The output result is as follows:
String (5) "scnjl" NULL
We can see that when using the global function, the variable $ a is not directly used. Instead, a variable pointing to the value of $ a is copied. Therefore, after unset, the global variable $ a is not unset, and $ GLOBALS ['A'] directly represents the global variable $.
This is the difference between global and GLOBALS.
?
Today, when I got something, I found that the global variable has no value in the class. I found it for a long time because the value in the file included in that class is not a global variable, because the file is included by another function, the variables in the include file in the class file are also local variables.
Example:
Test008.php
include 'test009.php';Class A {var $name;function __construct() {}function A() {$this->__construct();}function test() {var_dump($GLOBALS['var']);}function test1() {$this->test();}}$a = new A();
? Test009.php
$var = 'scnjl';
? Test010.php
class xx {function __construct() {}function test() {include 'test008.php';$a->test1();}}$xx = new xx();$xx->test();
? This is just a simple column. In fact, the values in test009.php can be directly put into test008.php.
Here, a null value is output.