我正在使用通过pecl从 apd.so 库中安装的ovverride_function
它似乎没有按预期工作
这是我的脚本
function my_require($path) {
echo "HELLOn";
echo $path;
}
$b = override_function('require', '$path', 'return my_require($path);');
var_dump($b);
require './index.php';
我期望看到的是输出
bool(true)
HELLO
./index.php
相反,我得到了
bool(true)
Warning: require(./index.php): failed to open stream: No such file or directory in /var/www/test/script/test.php on line 14
因此,即使该函数看起来有效(bool true),require函数仍然充当旧函数。
知道吗?
require
不是一个函数,它是一个语言结构,如function
或echo
。尝试调用require index.php
(没有()
),它在调用正常函数时仍然可以工作,而不会()
。文档没有明确说明它是,但它列在"控制结构"下,所以这就是为什么override_function
不适用于此require
(或任何其他语言结构)。