Object-Oriented Programing in PHP

Related Posts on PHP5 Tutorial – Object Oriented Programming (OOPS)
  1. Php Class Overview
  2. Defining Attributes of a PHP5 Class
  3. Defining Methods of a PHP5 Class
  4. Creating a PHP5 Constructor __construct()
  5. Creating a PHP5 Destructor __destruct()
  6. Php Class Access Specifiers – public, private and protected

Advance PHP5 Concepts
  1. $this variable in Php5
  2. instanceOf Operator in Php5
  3. Defining PHP5 Class Constants in Php5
  4. Static Data Members and Methods in Php5
  5. Final Class and Methods in Php5
  6. Exception Handling in PHP5
PHP5 Inheritance And Polymorphism And Abstract Class
  1. PHP Inheritance Concept
  2. Difference between Abstract Class and Interface
  3. PHP Polymorphism Concept
PHP5 has made a lot of improvements as regarding OOPS is concerned. Although it has not been up to the mark with the likes of Java, .NET and C++; but when compared to PHP4, PHP5 has made significant improvements.
In this post, I propose to cover the following topics:
  • About PHP5
  • Future Scope of PHP
  • New keywords in PHP5
  • A note on Garbage Collection
  • Naming Conventions
  • Note on E_STRICT
  • Built in Classes (SPL)

About PHP5

PHP5 has improved support for OOPS when compared to PHP4. The 4 pillars of OOPS are fully supported by PHP5 i.e. Encapsulation, Inheritance, Polymorphism and Abstraction. You can also create interfaces; if you have been designing classes for a while, you know how important interfaces are.

PHP5 also provides performance improvements as it has made significant changes to its core ‘C’ code. This means that the execution of PHP5 programs will now gain the needed performance improvement.

PHP5 has an integrated support for SOAP as it provides in-built classes for SOAP calls.

PHP5 offers Exception handling mechanism that was missing in its earlier version. You no longer have to write your own logic to return different type of values from one function to another in case of errors. You can now surround your code by try..catch blocks and write necessary logic inside your functions and raise an Exception. You can also extend from the existing Exception class to create your own Exception class.

Future Scope of PHP

PHP6 is in development as of July 2007 and the PHP team is considering to add namespaces support. For java developers, a namespace is an equivalent to packages. With PHP6 a lot of default options in php.ini will either be removed or be enabled. To name a few magic_quotes, safe_mode, register_mode will all be removed.

New keywords in PHP5
  1. interface
  2. implements
  3. public
  4. private
  5. protected
  6. abstract
  7. try
  8. catch
  9. throw
  10. clone
  11. this
  12. final
PHP5 introduces Garbage Collection

For those who don’t know what a Garbage Collection is; here is a note. Garbage Collection refers to the automatic reclamation of dynamically allocated object or variable that are no longer in accessible when an object or variable goes out of scope. An object/variable can goes out of scope only in the following circumstances:
  • when you explicitly unset() it
  • assign null to it
  • when the method/script has completed its execution
Note on E_STRICT

A new error level, E_STRICT, has been introduced and is especially useful in the context of PHP5 OOPS. It is a useful technique for discovering where your code may need upgrading (from PHP4 to PHP5). Error level E_ALL does not encompass E_STRICT and should be set explicitly in php.ini as follows.
error_reporting = E_ALL | E_STRICT
Build in classes (SPL – Standard PHP Library)

PHP5 introduces the Standard PHP Library (SPL), which provides a number of ready-made classes and interfaces. The type of classes PHP5 introduces are for Exceptions, Iterators, Web Services and PHP Data Objects (PDO).

These are ready-made classes that speeds up development. The core functionality behind these classes are written in C because of which it offers significant performance advantages.

This was a note on Introduction to PHP5 OOPS Features. As a continuation to this post, I have planned a complete tutorial on PHP5 OOPS features like classes, interfaces, inheritance, etc. Subscribe below to receive updates as a new tutorial goes live.

Please feel free to ask questions or comment on the post. You can also read the related posts below on PHP5 OOPS Tutorials.
You can provide your name and email address below to receive updates as and when new tutorials are published. Subscribe Below.

1 comment:

Unknown said...

You have share the great info. I like your post. Thanks for sharing the good points. I will recommend this info...
http://www.webwingtechnologies.com/hire-php-developers.html