02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

106<br />

CHAPTER 3 ■ OBJECT-ORIENTED PROGRAMMING<br />

}<br />

}<br />

$this->prop1 = $newval;<br />

protected function get<strong>Pro</strong>perty()<br />

{<br />

return $this->prop1 . "";<br />

}<br />

class MyOtherClass extends MyClass<br />

{<br />

public function __construct()<br />

{<br />

parent::__construct();<br />

echo "A new constructor in " . __CLASS__ . ".";<br />

}<br />

}<br />

public function newMethod()<br />

{<br />

echo "From a new method in " . __CLASS__ . ".";<br />

}<br />

public function call<strong>Pro</strong>tected()<br />

{<br />

return $this->get<strong>Pro</strong>perty();<br />

}<br />

// Create a new object<br />

$newobj = new MyOtherClass;<br />

// Call the protected method from within a public method<br />

echo $newobj->call<strong>Pro</strong>tected();<br />

?><br />

This generates the desired result:<br />

The class "MyClass" was initiated!<br />

A new constructor in MyOtherClass.<br />

I'm a class property!<br />

The class "MyClass" was destroyed.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!