开发者

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

开发者 https://www.devze.com 2023-01-25 05:16 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Override default php function
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

精彩评论

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