PHP 5.3 $this versus PHP 5.4
<p>I am calling a member function inside an anonymous function using $this.</p>

<pre><code> $this-&gt;exists($str)
</code></pre>

<p>PHP 5.4 does not give me problems, 5.3 gives me problems.</p>

<p>The error is</p>

<pre><code>&lt;b&gt;Fatal error&lt;/b&gt;:  Using $this when not in object context in
</code></pre>

<p>Here is my code  </p>

<pre><code>class WordProcessor
{

private function exists($str)
{
 //Check if word exists in DB, return TRUE or FALSE
 return bool;
}

private function mu_mal($str)
{

    if(preg_match("/\b(mu)(\w+)\b/i", $str))
    {   $your_regex = array("/\b(mu)(\w+)\b/i" =&gt; "");      
        foreach ($your_regex as $key =&gt; $value) 
            $str = preg_replace_callback($key,function($matches)use($value)
            {
                if($this-&gt;exists($matches[0])) //No problems in PHP 5.4, not working in 5.3
                    return $matches[0];
                if($this-&gt;exists($matches[2]))
                    return $matches[1]." ".$matches[2];
                 return $matches[0];
            }, $str);
    }
    return $str;
}

}
</code></pre>
