com");
$xemailer->addRecipients("hasin@somewherein.net");
->$xemailer->setSubject("Just a Test");
->$xemailer->setBody("Hi Hasin, How are you?");
->$xemailer->sendEmail();
->?>
Kick-Starting OOP
[ 24 ]
Now if you look carefully at the code of the ExtendedEmailer class, you will find
that we accessed the $sender property of its parent (which is actually Emailer class).
We have been able to access that property only because it was declared as protected.
One more benefit we get here, is that the property $sender is still inaccessible
directly from outside the scope of these two classes. That means if we execute the
following code, it will generate a fatal error.
include_once("class.emailer.php");
include_once("class.extendedemailer.php");
$xemailer = new ExtendedEmailer();
$xemailer->sender = "hasin@pageflakes.com";
?>
Upon execution, it gives the following error:
Fatal error: Cannot access protected property
extendedEmailer::$sender in
C:\OOP with
PHP5\Codes\ch1\test.php on line
5Constructors and Destructors
We discussed earlier in this chapter about the constructor method. A constructor
method is the method that executes automatically while creating instances of the
class.
Pages:
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45