New Object Oriented Features - By PHP Expert


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";
}
}
?>

No comments

Enter your email address:

Delivered by FeedBurner

OR

 Subscribe in a reader

 
Latest Blogs
 
 
 
Tips for optimizing php code by PHP Expert Important SERVER Variables in PHP - By PHP Expert Improved Error Messages in PHP 5 - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert New Object Oriented Features - By PHP Expert Object Overloading in PHP 5 Persistable Classes - By PHP Expert Dynamic Getter/Setter Methods - By PHP Expert New Functions in PHP 5 New Directives - By PHP Expert Exception Handling - By PHP Expert Password Encryption in PHP - By PHP Expert Output Buffering in PHP - By PHP Expert Page Excerpts Using CURL - By PHP Expert Quick and Easy Google Site Search - By PHP Expert Always Be Notified When Google Crawls Your Site - By PHP Expert How to POST Form Data using CURL - By PHP Expert Cryptography for web developers - By PHP Expert Dynamically Loading JavaScript Files - by PHP Expert What is Web 2.0 - By PHP Expert