Global variable inside of function <p>Code below prints produces error:</p> <pre><code>Notice: Undefined variable: x in C:\wamp\www\h4.php on line 9 </code></pre> <p>and output:</p> <pre><code>Variable x inside function is: Variable x outside function is: 5 </code></pre> <p>Code:</p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;?php $x = 5; // global scope function myTest() { // using x inside this function will generate an error echo "&lt;p&gt;Variable x inside function is: $x&lt;/p&gt;"; } myTest(); echo "&lt;p&gt;Variable x outside function is: $x&lt;/p&gt;"; ?&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What gets wrong with <code>x</code> global variable inside of <code>myTest</code> function?</p>