can't access global variables inside a usort function?
<p>I'm trying to do a usort in PHP, but I can't access global variables inside a usort function.</p>

<p>I've simplified my code down to bare bones to show what I mean:</p>

<pre><code>$testglobal = 1;
function cmp($a, $b) {
    global $testglobal;
    echo 'hi' . $testglobal;
}
usort($topics, "cmp");
</code></pre>

<p>Assuming the usort runs twice, my expectations is this will be the output:</p>

<pre><code>hi1hi1
</code></pre>

<p>Instead, my output is:</p>

<pre><code>hihi
</code></pre>

<p>I've read the manual (<a href="http://us.php.net/usort" rel="nofollow">http://us.php.net/usort</a>) and I don't see any limitations on accessing global variables. If I assign the usort to a variable that I echo, it outputs 1, so the usort is definitely running successfully (plus, there are all those "hi's").</p>

<p>Am I doing something incredibly stupid here? If not, is there a workaround?</p>
