Php global variable range?
<p>update:</p>

<p>the code i put below will be invoked by a form on other webpage. so that's why I didn't made a instance of a obj. </p>

<p>More detail code:</p>

<pre><code>$serverloc='serverURL';

class Aclass{

           function push(){
             global $serverloc;
             echo $serverloc;
             funNotinClass();
           } 

           function otherFunction(){

              echo $serverloc;

           }
}

funNotinClass(){

      echo $serverloc;
}
</code></pre>

<p>There is a Class contains 2 functiona "push()" and "otherFunction()" and there is independent function "funNotinClass()" and push() calls it. The class is for a web form in other page. When user click submit the form call the class and use the push() function. A weird thing I found is that the global var $serverloc is invisible to push() and funNotinClass()(they don't print out any thing), but otherFuction() which is a function just like puch() inside of the Aclass can just use the $serverloc(I dont even add global in front of it). How strange....anyone know what is the reason caused this?</p>

<p>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</p>

<p>I read many information about the scope of a global var in php.
they all say a global var is defined outside of function or class and you can use it by using global this key word.</p>

<p>So this is my code</p>

<pre><code>$serverloc='serverURL';

class Aclass{

function Afunction(){
 global $serverloc;
 echo $serverloc;

} 
}
</code></pre>

<p>but when I run this class it didn't print anything out.
Is that because I did something wrong or global var just doesn't work this way. Since all the example I read before are just access a global var in functions directly not a function in a class</p>
