25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

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

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

Object Oriented Programming in <strong>PHP</strong> ” 115<br />

In this case, both $myInstance and $copyInstance will point to the same object, even<br />

though we didn’t specify that we wanted this to happen by means of any special<br />

syntax. This is the standard behaviour of objects in most languages, but wasn’t the<br />

case in <strong>PHP</strong> 4, where objects were handled like any other normal variables and were,<br />

therefore, passed by value.<br />

Class Inheritance<br />

One of the key fundamental concepts of OOP is inheritance. This allows a class to extend<br />

another class, essentially adding new methods and properties, as well as overriding<br />

existing ones as needed. For example:<br />

class a {<br />

function test()<br />

{<br />

echo "a::test called";<br />

}<br />

function func()<br />

{<br />

echo "a::func called";<br />

}<br />

}<br />

class b extends a {<br />

function test()<br />

{<br />

echo "b::test called";<br />

}<br />

}<br />

class c extends b {<br />

function test()<br />

{<br />

parent::test();<br />

}<br />

}<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)<br />

class d extends c {<br />

function test()<br />

{<br />

b::test();<br />

}

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

Saved successfully!

Ooh no, something went wrong!