title: PHP What is the difference between $GLOBALS['variable']; and global $variable;
body: <p>Please look at the following two examples:</p>
  
  <p>Example 1:</p>
  
  <pre><code>$variable = 'some value';
  
  class Foo {
     public function bar() {
        global $variable;
        print $variable;       
     }
  }
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>$variable = 'some value';
  
  class Foo {
     public function bar() {
        print $GLOBALS['variable'];  
     }    
  }
  </code></pre>
  
  <p>Examples can be used like this:</p>
  
  <pre><code>$foo = new Foo();
  $foo-&gt;bar();
  </code></pre>
  
  <p>Both seem to do the same thing?  What is the difference?  Is one way better than the other?  Why are there two different ways of doing this?</p>
  
  <p>The first example seems strange to me because it looks like a declaration followed by using the variable without assigning it.. looks weird to me.</p>
  
  <p>Thank you.</p>