I have the below class in a 3rd party library which I am not supposed to modify.
<?php
class MyMailer {
public function send() {
$mail = new PHPMailer();
$mail->setFrom('[email protected]', 'Your Name');
$mail->addAddress('[email protected]', 'My Friend');
$mail->Subject = 'First PHPMailer Message';
$mail->Body = 'Hi! This is my first e-mail sent through PHPMailer.';
$mail->Send();
}
public function check(){
//code
}
}
How can I override or hook the send() method or how can I override the entire class MyMailer with my own new class?
The below link suggests to use runKit which is not bundled with PHP by default. So there is no guarantee that it's all available in all my servers. I learnt that this approach is called Monkey Patching.
All the answers are very old and I wish if there are any new solution available.
The Patchwork library is so easy and I make it work with few tries.