fate0 / xmark

A PHP7 extension that can hook most functions/classes and parts of opcodes
BSD 3-Clause "New" or "Revised" License
239 stars 32 forks source link

Ubuntu 18.04 默认环境下报错 #3

Closed fate0 closed 5 years ago

fate0 commented 5 years ago

@RicterZ 报告了在 Ubuntu 18.04 下使用 apt 安装的 apache2 和 php7,使用配置重命名函数名的时候,会出现 <b>Fatal error</b>: Cannot redeclare xxx() in xxx on line <b>xxx</b><br /> 错误信息,make test 也出现部分失败的问题

fate0 commented 5 years ago

出现 Cannot redeclare 的原因是和 opcache 扩展有冲突,在 opcache 拷贝原来 CG(function_table) 中各个函数到 ZCG(function_table) 的时候,并没有使用原来 CG(function_table) 中的 key 作为 ZCG(function_table) 的 key,而是直接使用 function->function_name,如下:

static int copy_internal_function(zval *zv, HashTable *function_table)
{
    zend_internal_function *function = Z_PTR_P(zv);
    if (function->type == ZEND_INTERNAL_FUNCTION) {
        zend_hash_update_mem(function_table, function->function_name, function, sizeof(zend_internal_function));
    }
    return 0;
}

我们之前并没有选择去修改函数本来的名字。

解决方案:修改原来 function/class 内的名字

fate0 commented 5 years ago

make test 部分失败的原因是 apt 安装的 PHP,json 并没有静态编译在 PHP 中,需要使用配置加载,但是在 make test 的时候,使用的是 php -n ... 去跑测试,所以并不会加载 json。

解决方案:使用其他内建函数替换 json_encode