Home > Article > Backend Development > Why are $GLOBAL[''] and the keyword global affected by static variables in PHP?
<code class="language-php"><span class="x">$a = 1;</span>
</code>
Read the PHP manual, there are many examplesVariable scope
The scope of a variable is the context in which it is defined (that is, its effective scope). Most of the
PHP variables have only a single scope. This single range span also contains
Files introduced by include and require. For example:
<code class="language-php"><span class="cp"><?php</span>
<span class="nv">$a</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
<span class="k">include</span> <span class="s1">'b.inc'</span><span class="p">;</span><span class="cp">?></span><span class="x"></span>
</code>
<code class="language-text">global $a;
时会 新建 一个指向与外部$a同地址的指针
$GLOBALS['a'] = &$static_a;
时会 把外部$a 指针 指向 $static_a的内容,抛弃原先的指向
</code>