开发者

PHP if function is called, how to override it with another function [duplicate]

This question already has answers here: Closed 11 years ago.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜