Home  >  Article  >  php教程  >  callback 的时候在有些php版本下报出Unable to call custom fun

callback 的时候在有些php版本下报出Unable to call custom fun

WBOY
WBOYOriginal
2016-06-06 19:43:251811browse

摘要: 接到一个站长反馈页面信息展示失败,拿到服务器权限开启调试一看,发现报错了,报错的地方是一个preg_replace_callback方法中Unable to call custom replacement function。而奇怪的是,其他系统其他地方的preg_replace_callback调用没有其他问题。后

摘要:

  接到一个站长反馈页面信息展示失败,拿到服务器权限开启调试一看,发现报错了,报错的地方是一个preg_replace_callback方法中Unable to call custom  replacement function。而奇怪的是,其他系统其他地方的preg_replace_callback调用没有其他问题。后经过测试发现是callback写法问题造成,特此记文。

 

正文:

     出现错误的代码调用,源代码书写如下:

$content = preg_replace_callback('/正则/', 'PwHook::_pregReplace', $content);

然而,采用array的方式书写则又正常:

1 $content = preg_replace_callback('/正则/', array(self, '_pregReplace'), $content);

而同样的第一种写法,在用call_user_func_array的方法中也在这台服务器上出现同样的Unable to call constom function的问题,同样改成第二种方法即可。

看来第一种写法还是会有什么问题,还是第二种方法靠谱点

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn