开发者

What is the easiest and/or "approved" way to replace a built-in PHP function? [duplicate]

开发者 https://www.devze.com 2023-03-01 23:57 出处:网络
This question already has answers here: 开发者_Go百科 Closed 11 years ago. Possible Duplicate: Redefine Built in PHP Functions
This question already has answers here: 开发者_Go百科 Closed 11 years ago.

Possible Duplicate:

Redefine Built in PHP Functions

Howdy!

As my servers do not have a locally available "sendmail" command, and I have written an api-compatible replacement mail() function, how do I actually go about replacing PHP's built-in mail() function? (Or others; there are a few that need replacement beyond that.)

Thanks!


Replacing mail is the wrong way to go about solving this problem.

If you need to send mail, but can't invoke the mail command, then you should use a third-party PHP mailing library that can use other methods. SwiftMailer is frequently recommended. It can use mail, invoke any sendmail-compatible binary or use an SMTP server directly. Further, it can be extended to send mail in any other way, thanks to a plugin architecture.

If you find yourself wanting to replace the PHP builtins, chances are that it's your code that is wrong, not PHP. Sure, some of the PHP builtins suck, but replacing the expected behavior of a function with your modified version is going to make future maintainers of your code want to murder you in your sleep.


You could in theory use the APD override_function to do this, but I would really really REALLY advise against doing that.

Is there any reason you can't just give your function a different name and use that name instead of mail?

If you absolutely insist, then http://php.net/manual/en/function.override-function.php


Check this out: http://php.net/manual/en/function.override-function.php

bool override_function ( string $function_name , string $function_args , string $function_code ) 

Overrides built-in functions by replacing them in the symbol table.


runkit_function_redefine(), but I wouldn't call it the "approved" way, since this shouldn't be done.

0

精彩评论

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