首页 > 关于preg_replace_callback中的匿名函数使用中遇到的问题

关于preg_replace_callback中的匿名函数使用中遇到的问题

最近升级php5.3到php5.6.19后,出现了一些弃用函数,比如:Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead。于是就着手修改,将其替换为preg_replace_callback。
事先当然了解一下其用法,但这个不是重点。当下出现的问题是:我改好后(贴出改完的代码),

/* replace special blocks by "{php}" */
        $source_content = preg_replace_callback($search, function ($r) {
            $str = $this->_quote_replace($this->left_delimiter);
            $str .= 'php';
            $str .= str_repeat("\n", substr_count($r[0], "\n"));
            $str .= $this->_quote_replace($this->right_delimiter);
            return $str;
        }, $source_content);

结果报Fatal error: Using $this when not in object context这个错误。
这里是实例化一个对象的结果。里面的函数也都不是静态的。
如何解决这个问题?


问题已解决,这个涉及到php的版本,在php5.4以上就没问题了。

【热门文章】
【热门文章】