如何修改内置php函数的返回值而不创建另一个名称的新函数并将所有使用过的函数重命名为新函数?例如
function time() {
return time()-1000;
}
当然这不会通过,是不是有像"函数时间()扩展时间(){}"或类似的东西?
使用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;
}
APD是用于调试目的的,所以对于产品代码,您不应该考虑使用这种技术。
你不能那样做。
考虑同时使用date_default_timezone_set()
和setlocale()
为什么要重写PHP的函数呢?如果某个函数不能完成您想要的工作,那么创建您自己的函数。如果它覆盖,使用不同的名称或创建一个类并将函数放在其中。
你想要达到的是一个错误的问题解决方案!!
一些例子将函数名time()
改为cTime()
(自定义时间)就像我为print_r()
创建自己的函数一样,printr()
以我的方式打印数组
或者类似
的东西class FUNCTIONS {
public function time() {
return time()-1000;
}
}
//Now access using
FUNCTIONS::time();