Skip to content

修正Habari检查PHP文件语法的一个BUG

2011 八月 20
by 荒野无灯

此BUG主要是Utils类中的php_check_file_syntax函数引起的。
PHP并没有规定说一定要有结束标记,而且,很多时候,结束标记会带来不必要的麻烦。
如CodeIgniter框架的code标准就规定不使用结束标志:PHP Closing Tag
不过,我目前在PHP5.3下测试,发现PHP貌似修复了该BUG :evil:
但是一直以来养成了不带结束标记的习惯了,因此,修正Habari这一BUG。因为用与不用结束标记应该是插件作者的自由。
修正后的函数如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    /**
     * Check the PHP syntax of (and execute) the specified file.
     *
     * @see Utils::php_check_syntax()
     */
    public static function php_check_file_syntax($file, &$error = null)
    {
        // Prepend and append PHP opening tags to prevent eval() failures.
        $content = file_get_contents($file);
        if (preg_match("/.*\?>$/i", $content))
        {
            $code = ' ?>' . $content . '<?php ';
        }
        else
        {
            $code = '
?>' . $content . '?><?php ';
        }
        return self::php_check_syntax($code, $error);
    }

喜欢这篇文章吗?

请订阅本站 RSS feed填写您的邮件地址,订阅我们的精彩内容:,欢迎点击这里捐赠以支持荒野无灯转播到腾讯微博 转播到腾讯微博

作者:荒野无灯
出处:Hacklog【Hacklog】

声明: 本站遵循 署名-非商业性使用-相同方式共享 3.0 共享协议. 转载请注明转自Hacklog【荒野无灯weblog】

本文链接: http://ihacklog.com/?p=4743

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <q cite=""> <strong>

 :wink:  :-|  :-x  :twisted:  :)  8-O  :(  :roll:  :-P  :oops:  :-o  :mrgreen:  :lol:  :idea:  :-D  :evil:  :cry:  8)  :arrow:  :-?  :?:  :!:

Note: You may use basic HTML in your comments. Your email address will not be published.

Subscribe to this comment feed via RSS