Moving towards PHP 5Moving towards PHP 5
|
 |
Visited: 954 |
| Not rated |
|
|
|
|
by Atul Jindal April 23, 2008
|
| Atul Jindal |
Working as Software Engineer.
Good Programming experience in various Languages.
Worked on various Web Technologies |
| Atul Jindal
has written 1 articles for PromotionWorld. |
| View all articles by Atul Jindal... |
The support for creating objects was from era of PHP3 but there was
only the limited support of OOPS. Originally OOPS support was only
meant to provide grouping of both data and functions together. As the
PHP popularity grew the OOPS need also grew.
There were many significant changes in PHP5. Earlier was a very
little support of encapsulation, and was only limited to grouping of
data and functions or I can say that all the implementation was visible
outside the class. But in PHP5 the concept of private and protected
member variables and methods was introduced. Now the data protection is
also possible with PHP5. The public, private and protected provide the
various access levels.
PHP5 provide support for the constructors and destructors via member
functions __construct and __destruct(). Constructors are the member
functions that are automatically called when the instance of class in
created. The earlier version of PHP the constructors were with the same
name as of the class name. This unified constructor scheme helps in
encapsulation of overridden subclass constructors. PHP 5 introduces a
destructor support similar to that of other object-oriented languages,
such as C++. The destructor method will be called as soon as all
references to a particular object are removed or when the object is
explicitly destroyed.
In PHP5 provides the concept of abstract classes and interfaces. For
an abstract class we cannot create an instance of a class. Only
non-abstract classes can be instantiated. For a methods defined
abstract, only the method's signature can be defined not their
implementation. Interface allows you to define certain methods, which a
class must implement. In interface we provide only the signature of
member functions but the definitions are provided in the class that
implements interface. The class that provides the implementation of an
interface must define all the methods of interface otherwise the error
will rise.
Like other programming languages there is also the support for final
and static keywords in PHP5.The final keyword does not allow class and
the member functions to be further extended. The classes declared with
final keyword cannot further extended. The member or method declared
with static keyword can't be accessed by the instance of object. Since
static methods are callable without an instance of the object created,
so $this is not available inside the method declared as static.
PHP5 has better error handling support. It provides exception model
similar to that of other programming languages like java or C#. An
exception can be thrown and caught. Code is surrounded by try block, to catch various exceptions. Each try must have at least one corresponding catch block. Normal execution (when no exception is thrown within the try block, or catch the matching exception thrown.
|