downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/reserved.variables.globals.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once
dirname(__FILE__) ."/toc/reserved.variables.inc";
$setup = array (
 
'home' =>
  array (
   
0 => 'index.php',
   
1 => 'PHP Manual',
  ),
 
'head' =>
  array (
   
0 => 'UTF-8',
   
1 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'reserved.variables.globals.php',
   
1 => '$GLOBALS',
  ),
 
'up' =>
  array (
   
0 => 'reserved.variables.php',
   
1 => 'Predefined Variables',
  ),
 
'prev' =>
  array (
   
0 => 'language.variables.superglobals.php',
   
1 => 'Superglobals',
  ),
 
'next' =>
  array (
   
0 => 'reserved.variables.server.php',
   
1 => '$_SERVER',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="reserved.variables.globals" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">$GLOBALS</h1>
  <p class="refpurpose"><span class="refname">$GLOBALS</span> &mdash; <span class="dc-title">References all variables available in global scope</span></p>

 </div>
 
 <a name="reserved.variables.globals.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <p class="para">
   An associative <a href="language.types.array.php" class="type array">array</a> containing references to all variables which
   are currently defined in the global scope of the script. The
   variable names are the keys of the array.
  </p>
 </div>

 
 <a name="reserved.variables.globals.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <var class="varname">$GLOBALS</var> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">test</span><span style="color: #007700">()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"local&nbsp;variable"</span><span style="color: #007700">;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'$foo&nbsp;in&nbsp;global&nbsp;scope:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$GLOBALS</span><span style="color: #007700">[</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">]&nbsp;.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'$foo&nbsp;in&nbsp;current&nbsp;scope:&nbsp;'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Example&nbsp;content"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">test</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents para"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
$foo in global scope: Example content
$foo in current scope: local variable
</pre></div>
    </div>
   </div><p>
  </p>
 </div>

 
 <a name="reserved.variables.globals.notes"></a><div class="refsect1 notes">
  <h3 class="title">Notes</h3>
  <blockquote><p><b class="note">Note</b>: This is a &#039;superglobal&#039;, or
automatic global, variable. This simply means that it is available in
all scopes throughout a script. There is no need to do
<strong class="command">global $variable;</strong> to access it within functions or methods.
<br /></p></blockquote>
  <blockquote><p><b class="note">Note</b>:
   <b>Variable availability</b><br />
  
    Unlike all of the other <a href="language.variables.superglobals.php" class="link">superglobals</a>,
    <var class="varname">$GLOBALS</var> has essentially always been available in PHP.
   <br />
  </p></blockquote>
 </div>

 
</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites