title: How to Access $this variable inside nested functions in codeigniter?
body: <p>I have a controller for Nu soap WSDL Like:</p>
  
  <pre><code>    class webservice extends CI_Controller
          {
          function index()
          {
                $this-&gt;load-&gt;library('encrypt');
                $this-&gt;load-&gt;model('MWSDl');
  //...
              function buy($apicode)
              {
                  if(!$this-&gt;MWSDl-&gt;check_gateway($apicode)) //Error occurred  php Cannot find "$this" Variable
              }
  //...
              $this-&gt;nusoap_server-&gt;service(file_get_contents("php://input"));
          }
      }
  </code></pre>
  
  <p>How to Access <code>$this</code> inside <code>buy</code> function?<br>
  I tried by <code>global $this</code> But Error occurred!<br>
  Error:<br>
  <code>Fatal error: Using $this when not in object context in \controllers\webservice.php on line 9</code> </p>