PHP:override_function即使返回bool true也不会覆盖 [英] PHP : override_function doesn't override even if bool true is returned

查看:329
本文介绍了PHP:override_function即使返回bool true也不会覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用通过pecl从apd.so库安装的ovverride_function



它似乎没有按预期工作



这是我的脚本

  function my_require($ path){
echoHELLO\ N;
echo $ path;
}


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

我的预期是看作输出

  bool(true)
HELLO
./index.php

取而代之的是

  bool(true)

Warning:require (./index.php):无法打开流:第14行/var/www/test/script/test.php中没有这样的文件或目录

所以,即使函数看起来有效(bool true),require函数仍然是旧函数。



任何想法?

解决方案

require 不是函数,它是一种语言像函数 echo 构造。尝试调用 require index.php (没有()),它在调用没有() wont。文档没有明确说明它是这样的,但它在控制结构下列出,所以 override_function 对于 require (或任何其他语言结构)。

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\n";
    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?

解决方案

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).

这篇关于PHP:override_function即使返回bool true也不会覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆