0

Possible Duplicate:
Override default php function

Is there a way to detect that a function is being called and override with a separate function? I'm not sure function_exists does that.

Community
  • 1
  • 1
tmartin314
  • 4,061
  • 10
  • 39
  • 60

3 Answers3

1

Override default php function

You can use namespaces to override existing function names:

namespace blarg;
function basename() {
    return 'whatever';
}
$base = basename();

I.e., any call to basename() within the blarg namespace will use your new version of the function.

Community
  • 1
  • 1
drudge
  • 35,471
  • 7
  • 34
  • 45
0

The override_function() function may be what you need, but it seems ugly.

However, using namespaces or inheritance are probably better options.

Carson Myers
  • 37,678
  • 39
  • 126
  • 176
0

Why do you want to? There is probably a better solution to the original problem.

Also, do you want to override a built in PHP function, or one that you have written yourself. Is it a method on an object, or a static function?

thelem
  • 2,642
  • 1
  • 24
  • 34