我知道在 C++ 或 Obj-c 等其他语言中甚至是可能的(在运行时和编译时),但是有没有办法在 php 中覆盖/重命名/重新映射函数?所以我的意思是,假设我们想要替换 mysql_query 的实现。这可能吗?
SOME_REMAP_FUNCTION(mysql_query, new_mysql_query);
//and then you define your new function
function new_mysql_query(blah...) {
//do something custom here
//then call the original mysql_query
mysql_query(blah...)
}
这样,其余代码就可以透明地调用 mysql_query 函数,而不知道我们在中间插入了一些自定义代码。
最佳答案
我相信,如果您使用命名空间,您可以编写一个具有相同名称的新函数,并以这种方式“欺骗”系统。这是我在上面读到的一篇简短的博客...
http://till.klampaeckel.de/blog/archives/105-Monkey-patching-in-PHP.html
关于php - 有没有办法在 php 中覆盖/重命名/重新映射函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3354190/