Using array_push in method in php
<p>The addRecipients use push_array but it does not work. What am I doing wrong here??</p>

<p>In class.emailer.php</p>

<pre><code>class Emailer
{
public $sender;
public $recipients;
public $subject;
public $body;

function __construct($sender)
{
    $this-&gt;sender = $sender;
    $this-&gt;recipients = array();
}

public function addRecipients($recipient)
{
    array_push($this-&gt;recipients, $recipient);
}

public function setSubject($subject)
{
    $this-&gt;subject = $subject;
}

public function setBody($body)
{
    $this-&gt;body = $body;
}

public function sendEmail()
{
    echo "From sendEmail, send email initiated&lt;br /&gt;";
    echo "Body: ".$this-&gt;body."&lt;br /&gt;";
    echo "Subject: ".$this-&gt;subject."&lt;br /&gt;";
    print_r ($this-&gt;sender);
    print_r ($this-&gt;recipients);
    echo "&lt;br /&gt;";
    foreach ($this-&gt;recipients as $recipient)
    {
        echo "6&lt;br /&gt;";
        //$result = mail($recipient, $this-&gt;subject, $this-&gt;body,"From: {$this-&gt;sender}\r\n");
        echo "7&lt;br /&gt;";
        if ($result) echo "Mail successfully sent to {$recipient}&lt;br/&gt;";
    }
}
</code></pre>

<p>}</p>

<p>And in class.extendedemailer.php</p>

<pre><code>include_once("class.emailer.php"); 

class ExtendedEmailer extends emailer
{
function  __construct(){
    //overwriting __contruct here   
}

public function setSender($sender)
{
    $this-&gt;sender = $sender;
}
}
</code></pre>

<p>And in sendemail.php</p>

<pre><code>    include_once("class.extendedemailer.php"); 
echo "start 1&lt;br /&gt;";
$xemailer = new ExtendedEmailer(); 

echo "1. adding sender: &lt;br /&gt;";
$xemailer-&gt;setSender("sender@mywebsite.com"); 
print_r ($xemailer-&gt;sender);
echo "&lt;br /&gt;2. adding recipients: &lt;br /&gt;";
$xemailer-&gt;addRecipients("recipientemail@gmail.com"); 
var_dump ($xemailer-&gt;recipients);
echo "&lt;br /&gt;3. adding subject: &lt;br /&gt;";
$xemailer-&gt;setSubject("Just a Test&lt;br /&gt;"); 
print_r ($xemailer-&gt;subject);
echo "4. adding body&lt;br /&gt;";
$xemailer-&gt;setBody("Hi, How are you?&lt;br /&gt;"); 
print_r ($xemailer-&gt;body);
echo "5. sending email&lt;br /&gt;";
$xemailer-&gt;sendEmail();
</code></pre>

<p>The output of recipients is NULL.</p>

<pre><code>start 1
1. adding sender: 
sender@mywebsite.com
2. adding recipients: 
NULL 
3. adding subject: 
Just a Test
4. adding body
Hi, How are you?
5. sending email
From sendEmail, send email initiated
Body: Hi, How are you?

Subject: Just a Test
</code></pre>
