Abstract classes
A class may be declared abstract to prevent it from being instantiated.
However, you may inherit from an abstract class:
abstract class MyBaseClass {
function display() {
print “Default display routine being called”;
}
}
Abstract methods.
A method may be declared abstract, thereby deferring its definition to an
inheriting class. A class that includes abstract methods must be declared
abstract:
abstract class MyBaseClass {
abstract function display();
}
Class type hints.
Function declarations may include class type hints for their parameters.
If the functions are called with an incorrect class type, an error occurs:
function expectsMyClass(MyClass $obj) {
}
Support for dereferencing objects that are returned from methods.
In PHP 4, you could not directly dereference objects that were returned
from methods. You had to first assign the object to a dummy variable and
then dereference it.
PHP 4:
$dummy = $obj->method();
$dummy->method2();
PHP 5:
$obj->method()->method2();
Iterators.
PHP 5 allows both PHP classes and PHP extension classes to implement
an Iterator interface. After you implement this interface, you can iterate
instances of the class by using the foreach() language
construct:
$obj = new MyIteratorImplementation();
foreach ($obj as $value) {
print “$value”;
}
