Is it possible to replace a function in php (such as mail) and make it do something else?

前端 未结 4 993
失恋的感觉
失恋的感觉 2020-11-28 11:45

I want to rewrite a function in PHP (let\'s say the mail() function), and want to make it so when I call mail() from now on, it will load my version of mail() and not the de

4条回答
  •  我在风中等你
    2020-11-28 12:34

    What you're referring to is generally called method overloading.

    While not generally supported by PHP, you actually may be able to redefine internal functions (as well as user functions) using runkit_function_remove() or runkit_function_redefine(). Of course to use that, you'll need to have pretty much full control over the PHP installation - since it's not bundled with PHP you'll need to install the runkit extension.

    Again, in a normal situation internal functions as well as user functions cannot be redefined (or overloaded) in PHP. This situation illustrates the benefit of wrapping some internal functions with a user function.

提交回复
热议问题