sasori Posted August 9, 2008 Share Posted August 9, 2008 hello, i created this 3 scripts as follows (question is at the bottom) //class.emailer.script and it works fine class emailer { protected $sender; private $subject; private $message; private $recipients; function __construct($sender) { $this->sender = $sender; $this->recipients = array(); } public function setSubject($subject) { $this->subject = $subject; } public function setMessage($message) { $this->message = $message; } public function addRecipients($recipient) { array_push($this->recipients,$recipient); } public function sendMail() { foreach($this->recipients as $recipient) { $result = mail($recipient, $this->subject,$this->message,"FROM: {$this->sender}\r\n"); if($result) echo "mail successfully sent to {$recipient}<br/>"; } } } //class.extendedmailer.php second script that extends the emailer class class ExtendedEmailer extends emailer { function __construct() { } public function setSender($sender) { $this->sender = $sender; } } ?> ///here is the trigger script to execute the 2 scripts above include_once('class.emailer.php'); include_once('class.extendedmailer.php'); $spam = new ExtendedEmailer(); $spam->setSender("nemo@gtalk.com"); $spam->setSubject("777777"); $spam->setMessage("testing ulit"); $spam->addRecipients("nemo.md5@gmail.com"); $spam->sendMail(); now the question is, how come there is this error Warning: array_push() [function.array-push]: First argument should be an array in C:\wamp\www\test2\oop\class.emailer.php on line 29 Warning: Invalid argument supplied for foreach() in C:\wamp\www\test2\oop\class.emailer.php on line 34 whenever i tried to use the setSender() of the class.extendedmailer.php, but when it is not included in the trigger script and i instantiate the class.emailer.php alone, everything works fine and the email is being sent ... kindly tell me the problem by the way, i leaved the extendedmailer.php constructor so that i can make use of the setSender function of it, but it seems it did go the right way Quote Link to comment https://forums.phpfreaks.com/topic/118902-solved-extends-help/ Share on other sites More sharing options...
Kieran Menor Posted August 9, 2008 Share Posted August 9, 2008 It might be caused because you omitted $this->recipients = array(); in your constructor Quote Link to comment https://forums.phpfreaks.com/topic/118902-solved-extends-help/#findComment-612271 Share on other sites More sharing options...
ratcateme Posted August 9, 2008 Share Posted August 9, 2008 i am not exactly sure but i think by calling ExtendedEmailer() rather than emailer the __construct in emailer doesn't run so $recipients never becomes a array. can't you just put that function into the main class and do away with the extend Scott. Quote Link to comment https://forums.phpfreaks.com/topic/118902-solved-extends-help/#findComment-612272 Share on other sites More sharing options...
sasori Posted August 9, 2008 Author Share Posted August 9, 2008 even if some errors occur, the email is still being sent,. however, these scripts are written in a book , i followed exactly, i just changed the variables,.thanks for the helps Quote Link to comment https://forums.phpfreaks.com/topic/118902-solved-extends-help/#findComment-612274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.