Jump to content

[SOLVED] extends help


sasori

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("[email protected]");
$spam->setSubject("777777");
$spam->setMessage("testing ulit");
$spam->addRecipients("[email protected]");
$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.