PHP if function is called, how to override it with another function [duplicate]
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 doe开发者_StackOverflows that.
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.
The override_function() function may be what you need, but it seems ugly.
However, using namespaces or inheritance are probably better options.
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?
精彩评论