While naming a class, follow the same naming convention as variables,
i.e. you can't start with a numeric letter, etc.
After that we declared the properties of this class. There are four properties here,
namely, $sender, $recipient, $subject, and $body. Please note that we declare
each of them with a keyword private. A private property means that this property
can only be accessed internally from this class. Properties are nothing but variables
inside a class.
If you remember what a method is, it is just a function inside the class. In this
class there are five functions, __construct(), addRecipient(), setSubject(),
setBody(), and sendEmail(). Please note that the last four methods are declared
public. That means when someone instantiates this object, they can access
these methods.
The __construct() is a special method inside a class which is called constructor
method. Whenever a new object is created from this class, this method will execute
automatically. So if we have to perform some preliminary tasks in our object while
initiating it, we will do from this constructor method. For example, in the constructor
method of this Emailer class we just set the $recipients as a blank array and we
also set the sender name.
Pages:
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40