Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/118902-solved-extends-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/118902-solved-extends-help/#findComment-612272
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.