Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 default php version. Is this possible in php?

The reason I want to do this is because I have thousands of lines of code which call mail() and I don't want to rewrite all of them.

Also for future reference, in computer programming, what is it called when you do something like this?

like image 912
chris Avatar asked Dec 03 '09 01:12

chris


People also ask

How do you check PHP mail function is working or not?

to check if it is sending mail as intended; <? php $email = "[email protected]"; $subject = "Email Test"; $message = "this is a mail testing email function on server"; $sendMail = mail($email, $subject, $message); if($sendMail) { echo "Email Sent Successfully"; } else { echo "Mail Failed"; } ?>

How does PHP mail work?

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters. mail( to, subject, message, headers, parameters );

What is purpose of function in PHP?

A function is a piece of code that takes another input in the form of a parameter, processes it, and then returns a value. A PHP Function feature is a piece of code that can be used over and over again and accepts argument lists as input, and returns a value. PHP comes with thousands of built-in features.


1 Answers

There is an extension that allows you to override functions. It is meant to be used for debugging, but I guess you can use it for your needs. Take a look:

http://www.php.net/manual/en/function.override-function.php

If you wish to call the original function within your version, make sure you read this comment: http://no.php.net/manual/en/function.override-function.php#50821

like image 197
Milan Babuškov Avatar answered Oct 01 '22 18:10

Milan Babuškov