如何"注入"内置的php函数

gad*_*lat 2 php function inject built-in extend

如何在不创建具有其他名称的新函数的情况下修改内置php函数的返回值,并将以前名称的所有已使用函数重命名为新函数?例如

function time() {
    return time()-1000;
}
Run Code Online (Sandbox Code Playgroud)

当然这不会通过,是不是有像"function time()extends time(){}"之类的东西?

Pau*_*xon 5

使用APD PECL扩展,您可以重命名覆盖内置函数.

//we want to call the original, so we rename it
rename_function('time', '_time()');

//now replace the built-in time with our override
override_function('time', '', 'return my_time();');

//and here's the override
function my_time($){
        return _time()-1000;  
}
Run Code Online (Sandbox Code Playgroud)

APD用于调试目的,因此这不是您应该考虑的生产代码技术.