Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6052733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:57:39+00:00 2026-05-23T07:57:39+00:00

class emailer { private $sender; private $recipients; private $subject; private $body; function __construct($sender) {

  • 0
class emailer
{
private $sender;
private $recipients;
private $subject;
private $body;
function __construct($sender)
{
$this->sender = $sender;
$this->recipients = array();
}
public function addRecipients($recipient)
{
array_push($this->recipients, $recipient);
}
public function setSubject($subject)
{
$this->subject = $subject;
}
public function setBody($body)
{
$this->body = $body;
}
public function sendEmail()
{
foreach ($this->recipients as $recipient)
{
$result = mail($recipient, $this->subject, $this->body,
"From: {$this->sender}\r\n");
if ($result) echo "Mail successfully sent to
{$recipient}<br/>";
}
}
}

why the code write this function?

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

could i delete it? thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:57:40+00:00Added an answer on May 23, 2026 at 7:57 am

    Based on your comment to the question…

    That function is called a constructor. Take a look at its form:

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

    Walking through what it’s doing, the first thing you see is that it has a standardized name. In this case, __construct is reserved by the language to specify that this function is used to build an instance of an object described by this class.

    Next, note that it accepts a parameter. This means that when you create an instance of the class, you’d supply that instance with a parameter. So when you create an instance, you’d do something like this:

    $obj = new emailer($someSender);
    

    What you’re doing here is creating an instance of emailer and supplying it a sender parameter. This call to new is what invokes the constructor. (Essentially, it’s “constructing” a “new” instance of emailer.)

    Internal to the constructor, it’s doing two things:

    1. Set the sender property on the object to the $someSender which was provided in the call to new.
    2. Initialize the recipients property to a new array.

    Finally, note that this function doesn’t return anything. It’s a standardized function reserved by the language, and an implication is that what it’s “returning” is a new instance of that class. In the example call above, this instance is being set to $obj.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

class Application_Form_ImageUpload extends Zend_Form { protected $user_id; function __construct($id){ $this->user_id = $id; } public
When should I use the this -keyword for properties in code? public class MyClass
class A; class B { public: B(A& a) : a(a) {} private: A& a;
Class.method = function () { this.xx } Class.prototype.method = function () { this.xx }
class CommandManager { public: void sendText(std::string command); static bool CommandManager::started; private: bool parseCommand(std::string commands);
class myClass { public $user=array( 'first_name' => 'Andi', 'last_name' => 'Abdulloh', 'result' => array('A','B','C','D','E'));
class foo { public: void set(const int a) {b=a;} private: int b; }; Here
class Array { double *mx; int mn; public: Array(); ~Array(){delete []mx}; Array& operator-(Array& b);
class SignUp { var $pass; var $repass; var $eMail; var $userName; function __construct($p,$rep,$uName,$mail) {
class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.