Press "Enter" to skip to content

PHP Reflection Extension的一个bug

今天同事eddix告诉我发现一个PHP的warning,

$php --re dummy
Warning: Internal error: Cannot find extension function Dummy
in global function table in Unknown on line 0

以前没有遇到过, 不知道什么意思.
经过翻看代码, 发现了一个reflection extension的Bug:
同事自己写的扩展中, 在module entry中注册的function table里的funcion是大小写的, 类似于上面出错信息中的Dummy,
而我们都知道, PHP的function_table中的函数都是小写的(参看我之前的文章深入理解PHP原理之函数(Introspecting PHP Function)).
于是reflection extension的如下这段代码就会报错:

 if (module->functions && module->functions->fname) {
        //有省略
        while (func->fname) {
            if (zend_hash_find(EG(function_table),
                //注意这里, 没有小写化函数名.
                func->fname, strlen(func->fname) + 1, (void**) &fptr) == FAILURE) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING,
                      "Internal error: Cannot find extension function %
                      in global function table", func->fname);
                func++;
                continue;
            }
    //有省略
    }

注意看, 在EG(function_table)中查找的时候, 并没有小写化func->fname, 就导致找不到了..
呵呵, 小bug, 已经report了: http://bugs.php.net/bug.php?id=54347

5 Comments

  1. 1v1 battle
    1v1 battle October 26, 2021

    哦 !! 这是一篇非常棒的文章。 感谢您提供这些详细信息。 我很遗憾我什至不知道这件事。

  2. 雪候鸟
    雪候鸟 March 23, 2011

    @cataphrac I can’t agree with you more~

  3. cataphrac
    cataphrac March 23, 2011

    This should still probably be fixed, but the functions should be declared with lowercase names. If you search for PHP_FE in lxr.php.net, you’ll notice this is always the case.
    In any case, since zend_register_functions does a lowercasing of the function names in the module list, the reflection ext should do it too. But for forward compatibility (in the future we may want to reduce the points where names are lowercased), it would be best if the extension follows the convention.

  4. 雪候鸟
    雪候鸟 March 23, 2011

    @fy 你说的也有道理哈,嘿嘿

  5. fy
    fy March 22, 2011

    ‘PHP的function_table中的函数都是小写的’ ,是不是这么理解:算是约定,只能自定义小写函数名,所以不是bug?:)

Comments are closed.