最新 php5.4 是 php5.4.22尝试回调函数不使用闭包形式如果依然不能解决问题,可去 php 的 bug 网站提交 bug

解决方案 »

  1.   

    很多人提交 这个bug了,我去看过了。
      

  2.   

    如果是:
    先 preg_match_all
    再 preg_replace
    也会出问题吗?
      

  3.   

    怎么实现的?
    原框架错误代码如下:注意【preg_replace_callback】的使用
                    if (! $closeTag)
                    {
                        $patterns = '/' . $begin . $parseTag . $n1 . '\/(\s*?)' . $end . '/is';
                        $content = preg_replace_callback($patterns, function  ( $matches ) use( $tLib , $tag , $that )
                        {
                            return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]);
                        }, $content);
                    } else
                    {
                        $patterns = '/' . $begin . $parseTag . $n1 . $end . '(.*?)' . $begin . '\/' . $parseTag . '(\s*?)' . $end . '/is';
                        for ($i = 0; $i < $level; $i ++)
                        {
                            $content = preg_replace_callback($patterns, function  ( $matches ) use( $tLib , $tag , $that )
                            {
                                return $that->parseXmlTag($tLib, $tag, $matches[1], $matches[2]);
                            }, $content);
                        }
                    }
      

  4.   

    既然 preg_replace_callback 会有内存泄露
    那么应该在任何文件中都是这样的你可以单独用一个文件测试一下
    $content = preg_replace_callback('/[a-z]/', function  ( $matches )  {
                            return strtoupper($matches[0]);
                        }, 'abdfrew');
    echo $content;与之等价的分立代码为
    $content = 'abdfrew';
    preg_match_all('/[a-z]/', $content, $matches );
    foreach($matches[0] as $v) $r[$v] = strtoupper($v);
    $content = strtr($content, $r);
    echo $content;
    先分别运行一下,看有无问题