Accessing a property inside a function defined in a method in PHP : <p>I need to call a function inside a method. This function needs access to a private property. This code:</p>

<pre><code>class tc {
  private $data=123;

  public function test() {
    function test2() {
      echo $this-&gt;data;
    }

    test2();
  }
}

$a=new tc();
$a-&gt;test();
</code></pre>

<p>returns the following error:</p>

<p><strong>Fatal error: Using $this when not in object context in ... on line ...</strong></p>

<p>Using PHP 5.6.38. How can I do this?</p>
