New Object Oriented Features - By PHP Expert


Support for dereferencing objects which are returned from methods.
In PHP 4, you could not directly dereference objects which are returned from methods. You would have 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. Once you implement this interface you will be able to iterate instances of the class by using the foreach() language construct.

$obj = new MyIteratorImplementation();
foreach ($obj as $value) {
print "$value";
}

For a more complete example, please refer to the "Advanced OOP & Design Patterns" chapter.

 __autoload()
Many developers writing object-oriented applications create one PHP source file per-class definition. One of the biggest annoyances is having to write a long list of needed includes at the beginning of each script (one for each class). In PHP 5, this is no longer necessary. You may define an __autoload() function which is automatically called in case you are trying to use a class which hasn't been defined yet. By calling this function the scripting engine is giving a last chance to load the class before PHP bails out with an error.

function __autoload($class_name) {
include_once($class_name . "php");
}

$obj = new MyClass1();
$obj2 = new MyClass2();

nilesh@sdi.la
2008-08-27 03:28:24
Nice Blog Keep it up
nilesh@sdi.la
2008-08-26 14:52:22
Nice Comment By Nilesh Pawar

Enter your email address:

Delivered by FeedBurner

OR

 Subscribe in a reader

 
  The lack of Unicode su
 
History PHP-GTK was origina