PHP语言, PHP扩展, Zend引擎相关的研究,技术,新闻分享 – 左手代码 右手诗

22 Mar 11 PHP Reflection Extension的一个bug


$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);

注意看, 在EG(function_table)中查找的时候, 并没有小写化func->fname, 就导致找不到了..

呵呵, 小bug, 已经report了:


Related Posts:

Tags: , ,

4 Responses to “PHP Reflection Extension的一个bug”

  1. 雪候鸟 |

    @cataphrac I can’t agree with you more~

  2. cataphrac |

    This should still probably be fixed, but the functions should be declared with lowercase names. If you search for PHP_FE in, 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.

  3. 雪候鸟 |

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

  4. fy |

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

Leave a Reply