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.

254 ” Differences Between <strong>PHP</strong> 4 and 5<br />

Objects<br />

• For all intents and purposes, all objects in <strong>PHP</strong> 5 are passed by reference. This<br />

means that assigning an object to a variable will not create a copy of the former,<br />

but simply creates another reference to it.<br />

• Constants, as well as static methods and properties, can now be defined within<br />

the scope of a class.<br />

• Class methods and properties now feature visibility, and can be declared as<br />

public, private or protected. Classes and methods can also be declared as<br />

final to prevent further inheritance.<br />

• Since all objects are assigned by reference, you now need a specialized mechanism<br />

to copy objects. This is provided by the clone construct and the __clone()<br />

magic method.<br />

• <strong>PHP</strong> 5 features unified constructors and destructors—all constructors should<br />

now be named __construct(), and the new __destruct() magic method has<br />

been added for object destruction.<br />

• With the addition of interfaces and abstract classes, <strong>PHP</strong> developers now have<br />

far greater control over how they implement their object-oriented code. Interfaces<br />

can be used to define common APIs, while abstract classes provide<br />

models for class implementations that follow a specific blueprint.<br />

• Class definitions can now be loaded on demand by using the __autoload()<br />

function.<br />

Magic Methods<br />

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

A multitude of new “magic” methods has been introduced in <strong>PHP</strong> 5:<br />

• __get() and __set() are called when accessing or assigning an undefined object<br />

property, while __call() is executed when calling a non-existent method<br />

of a class.

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

Saved successfully!

Ooh no, something went wrong!