Access a variable nested in a function inside a class in php
<p>Here is a cut down version of my code with the main <code>class</code> and main <code>function</code></p>

<p>I need to get the value of <code>'userName'</code> that input by the user to use it inside <code>'mainFunction'</code>, tried making the <code>'userName'</code> inside <code>'myForm'</code> global but that didn't get the value out.</p>

<p>can value of <code>'userName'</code> be available out side <code>'mainClass'</code> so that I can use it anywhere?</p>

<pre><code> class mainClass {

  function myForm() {
      echo '&lt;input type="text" value="'.$userName.'" /&gt;';
   }

 }   
 function mainFunction () {
    $myArray = array (

         'child_of' =&gt; $GLOBALS['userName']

      ) 
 }
</code></pre>
