dtlh12053 2012-10-05 09:15
浏览 52
已采纳

PHP:即使返回bool true,override_function也不会覆盖

I'm using the ovverride_function installed from apd.so library via pecl

It doesn't seem to work as expected

This is my script

function my_require($path) {
    echo "HELLO
";
    echo $path;
}


$b = override_function('require', '$path', 'return my_require($path);');
var_dump($b);
require './index.php';

What I expected was to see as output

bool(true)
HELLO
./index.php

Instead I got

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

So even if the function seemed to work (bool true) the require function still acts as the old one.

Any idea?

  • 写回答

1条回答 默认 最新

  • douchun5969 2012-10-05 11:30
    关注

    require is not a function, it's a language construct like function or echo. Try calling require index.php (without the ()), it will still work while calling a normal function without the () wont. The documentation does not explicitly says it is, but it is listed under "Control Structures", so that is why override_function does not work for this require (or any other language constructs).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?
  • ¥15 苹果手机突然连不上wifi了?
  • ¥15 cgictest.cgi文件无法访问
  • ¥20 删除和修改功能无法调用