title: PHP global in functions
body: <p>What is the utility of the <a href="http://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.global">global keyword</a>?</p>
  
  <p>Are there any reasons to prefer one method to another?</p>
  
  <ul>
  <li>Security?</li>
  <li>Performance?</li>
  <li>Anything else?</li>
  </ul>
  
  <p>Method 1:</p>
  
  <pre><code>function exempleConcat($str1, $str2)
  {
    return $str1.$str2;
  }
  </code></pre>
  
  <p>Method 2:</p>
  
  <pre><code>function exempleConcat()
  {
    global $str1, $str2;
    return $str1.$str2;
  }
  </code></pre>
  
  <p>When does it make sense to use <code>global</code>?</p>
  
  <p>For me, it <a href="http://www.php.net/manual/en/language.variables.scope.php#language.variables.scope.references">appears to be dangerous</a>... but it may just be a lack of knowledge.  I am interested in <strong>documented</strong> (e.g. with example of code, link to documentation...) technical reasons.</p>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <h3>Bounty</h3>
  
  <p>This is a nice general question about the topic, I (@Gordon) am offering a bounty to get additional answers. Whether your answer is in agreement with mine or gives a different point of view doesn't matter. Since the <code>global</code> topic comes up every now and then, we could use a good "canonical" answer to link to.</p>