PHP script structure and scope to avoid unnecessary function arguments
<p>Lets say you have an program like this:</p>

<pre><code>$info = array(
    'username'=&gt;'jeff',
    'password'=&gt;'kay'
);

function authenticate($user, $pass) {
    if($user == $info['username'] &amp;&amp; $pass == $info['password']) {
        return true;
    }
    return false;
}
</code></pre>

<p>This code won't work because the <code>$info</code> array isn't in <code>authenticate()</code>'s scope. You would have to pass <code>$info</code> as a parameter of <code>authenticate()</code> like so:</p>

<pre><code>function authenticate($info, $user, $pass) { // ... }
</code></pre>

<p><strong>This feels wrong to me.</strong></p>

<p>I could certainly add <code>global $info;</code> inside of <code>authenticate</code> but that feels <em>even more wrong</em>. What is best practice for structuring a PHP program to avoid scope issues like this? You don't see functions requiring you to pass in the 'global' object in modern code it seems like. How do I avoid unnecessary function arguments?</p>
