The new object oriented features are too numerous to give a detailed description in this section. The object oriented language chapter goes over each feature in detail.
The following is a list of the main new features:
1. public/private/protected access modifiers for methods and properties
Allows the use of common OO access modifiers to control access to methods and properties.
class MyClass {
private $id = 18;
public function getId() {
return $this->id;
}
}
$myclassobject=new MyClass();
echo $myclassobject->getId();
2. Unified constructor name __construct()
Instead of the constructor being the name of the class, it should now be declared as __construct(), making it easier to shift classes inside class hierarchies.
class MyClass {
function __construct() {
print "Inside constructor";
}
}
3. Object destructor support by defining a __destructor() method
Allows defining a destructor function that runs when an object is destroyed.
<?php
class MyClass {
function __destruct() {
print "Destroying object";
}
}
?>