Prev | Current Page 32 | Next

Hasin Hayder

"Object-Oriented Programming with PHP5"

emailer.php on line
43

That means you can't access any private property or method from outside the class.
Public: Any property or method which is not explicitly declared as private or
protected is a public method. You can access a public method from inside or outside
the class.
Protected: This is another modifier which has a special meaning in OOP. If any
property or method is declared as protected, you can only access the method from its
subclass. We will learn details about subclass later in this chapter. But to see how a
protected method or property actually works, we'll use the following example:
To start, let's open class.emailer.php file (the Emailer class) and change the
declaration of the $sender variable. Make it as follows:
protected $sender
Now create another file name class.extendedemailer.php with the
following code:
class ExtendedEmailer extends emailer
{
function __construct(){}
public function setSender($sender)
{
$this->sender = $sender;
}
}
?>
Now use this object like this:
include_once("class.emailer.php");
include_once("class.extendedemailer.php");
$xemailer = new ExtendedEmailer();
$xemailer->setSender("hasin@pageflakes.


Pages:
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44