25.09.2014 Views

ZEND PHP 5 Certification STUDY GUIDE

Create successful ePaper yourself

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

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

Strict Standards: Accessing static property foo::$bar as non static in<br />

<strong>PHP</strong>Document1 on line 1<br />

It is necessary for the static definition to follow the visibility definition; if no visibility<br />

definition is declared, the static method or property is considered public.<br />

i<br />

Class Constants<br />

Class constants work in the same way as regular constants, except they are scoped<br />

within a class. Class constants are public, and accessible from all scopes; for example,<br />

the following script will output Hello World:<br />

class foo {<br />

const BAR = "Hello World";<br />

}<br />

echo foo::BAR;<br />

Note that class constants suffer from the same limitations as regular constants—therefore,<br />

they can only contain scalar values.<br />

Class constants have several advantages over traditional constants: since they are<br />

encapsulated in a class, they make for much cleaner code, and they are significantly<br />

faster than those declared with the define() construct.<br />

Interfaces & Abstract Classes<br />

Yet another new feature added to <strong>PHP</strong> 5 is that of Interfaces and Abstract classes.<br />

These are both used to create a series of constraints on the base design of a group of<br />

classes. An abstract class essentially defines the basic skeleton of a specific type of<br />

encapsulated entity—for example, you can use an abstract class to define the basic<br />

concept of “car” as having two doors, a lock and a method that locks or unlocks the<br />

Licensed to 482634 - Amber Barrow (itsadmin@deakin.edu.au)

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

Saved successfully!

Ooh no, something went wrong!