我有一个PHP应用程序,包含大量行和gettext调用,例如_("some text")
有没有办法重载这个_(“”)运算符来执行一些运行时检查?类似的东西:
function _($argument) {
$result = _($argument); // this would be the non-overloaded _()
/* perform some checks or logging */
return $result;
}
答案 0 :(得分:4)
命名空间:
namespace myUnderscore;
function _($argument) {
$result = \_($argument); // this would be the non-overloaded _()
/* perform some checks or logging */
return strrev($result);
}
$argument = 'gazebo';
echo _($argument) . PHP_EOL; // call overloaded _()
echo \_($argument) . PHP_EOL; // call non-overloaded _()