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.

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

point, your destructor will be executed. However, there is no way to determine the<br />

order in which any two objects in your scripts will be destroyed. This can sometimes<br />

cause problems when an object depends on another to perform one or more<br />

functions—for example, if one of your classes encapsulates a database connection<br />

and another class needs that connection to flush its data to the database, you should<br />

not rely on your destructors to perform a transparent flush to the database when<br />

the object is deleted: the instance of the first class that provides database connectivity<br />

could, in fact, be destroyed before the second, thus making it impossible for the<br />

latter to save its data to the database.<br />

i<br />

Visibility<br />

<strong>PHP</strong> 5 adds the notion of object method and property visibility (often referred to as<br />

“PPP”), which enables you to determine the scope from which each component of<br />

your class interfaces can be accessed.<br />

There are four levels of visibility:<br />

public<br />

protected<br />

private<br />

final<br />

The resource can be accessed from any scope.<br />

The resource can only be accessed from within the class<br />

where it is defined and its descendants.<br />

The resource can only be accessed from within the class<br />

where it is defined.<br />

The resource is accessible from any scope, but cannot be<br />

overridden in descendant classes.<br />

The final visibility level only applies to methods and classes. Classes that are declared<br />

as final cannot be extended.<br />

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

Typically, you will want to make all API methods and properties public, since you<br />

will want them to be accessible from outside of your objects, while you will want to<br />

keep those used for internal operation as helpers to the API calls protected or private.<br />

Constructors and Destructors—along with all other magic methods (see below)—will<br />

normally be declared as public; there are, however, times when you wish

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

Saved successfully!

Ooh no, something went wrong!