-1

I ve a function in a class that replaces patterns. part of the function is below.

$text = preg_replace_callback('/\[dekanlik\]/',function (){return $this->dekanlik();},$text);

dekanlik() is another function in that class which lists the members.

works in local (PHP Version 5.4.21) but not work in server (PHP Version 5.3.3)

any suggestion?

zzlalani
  • 21,360
  • 16
  • 42
  • 72
JuST4FuN
  • 1
  • 1

1 Answers1

0

Being able to reference the context of an anonymous function (i.e. use $this) has been added in PHP 5.4. Before than the common workaround was:

$that = $this;
... function () use ($that) { return $that->foo(); } ...
deceze
  • 491,798
  • 79
  • 706
  • 853