1

I have a PHP application with tons of lines and gettext calls such as _("some text")

Is there a way to overload this _("") operator to perform some runtime checks? Something like:

function _($argument) {

    $result = _($argument); // this would be the non-overloaded _()

    /* perform some checks or logging */

    return $result;
}
David
  • 1,898
  • 2
  • 14
  • 32
  • You can't do it as you want. http://stackoverflow.com/questions/4697705/php-function-overloading – naththedeveloper Nov 22 '13 at 09:53
  • There is no way in PHP to redeclare function. You will get error "function with given name already exists". You can either use namespaces like Mark said below, or just make another function. – Stalinko Nov 22 '13 at 09:54

1 Answers1

4

Namespacing perhaps:

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 _()
Mark Baker
  • 209,507
  • 32
  • 346
  • 385