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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

100<br />

CHAPTER 3 ■ OBJECT-ORIENTED PROGRAMMING<br />

}<br />

}<br />

// Create a new object<br />

$newobj = new MyOtherClass;<br />

// Output the object as a string<br />

echo $newobj->newMethod();<br />

// Use a method from the parent class<br />

echo $newobj->get<strong>Pro</strong>perty();<br />

?><br />

Upon reloading the test file in your browser, the following is output:<br />

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

From a new method in MyOtherClass.<br />

I'm a class property!<br />

The class "MyClass" was destroyed.<br />

Overwriting Inherited <strong>Pro</strong>perties <strong>and</strong> Methods<br />

To change the behavior of an existing property or method in the new class, you can simply overwrite it<br />

<strong>by</strong> declaring it again in the new class:<br />

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

Saved successfully!

Ooh no, something went wrong!