PHP5 OOPS Tutorial - Introduction to PHP5 OOPS Features

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 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 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

  • final
  • interface
  • implements
  • public
  • private
  • protected
  • abstract
  • clone
  • try
  • catch
  • throw
  • this

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.

Related Posts on PHP5 Tutorial - Object Oriented Programming (OOPS)

  1. PHP5 Tutorial - Learn to create a PHP5 Class
  2. PHP5 Tutorial - Learn to Create a PHP5 Class Object
  3. PHP5 Tutorial - Defining Attributes of a PHP5 Class
  4. PHP5 Tutorial - Defining Methods of a PHP5 Class
  5. PHP5 Tutorial - Creating a PHP5 Constructor __construct()
  6. PHP5 Tutorial OOPS - Creating a PHP5 Destructor __destruct()
  7. PHP5 Tutorial OOPS - PHP5 Class Access Specifiers - public, private and protected
  8. PHP5 Tutorial - Magic Methods - __toString() method
  9. PHP5 Tutorial - Magic Methods - __get() and __set()
  10. PHP5 Tutorial - Magic Methods - __isset() and __unset()
  11. PHP5 Tutorial - Magic Methods - __call() method
  12. PHP5 Tutorial - Magic Methods - __autoload() method
  13. PHP5 Tutorial - Magic Methods - __sleep() and __wakeup()
  14. PHP5 Tutorial - Magic Methods - __clone() method

Your email:  
Subscribe Unsubscribe  

del.icio.us Reddit Slashdot Digg Facebook Technorati Google StumbleUpon Windows Live Furl Netscape Yahoo Bloglines Bookmark.it Ask Spurl Diigo

4 Responses to “PHP5 OOPS Tutorial - Introduction to PHP5 OOPS Features”

  1. Great post, Loved it a lot. I’ve never tried SOAP, I may look into it. PHP 6 yeah can’t wait, there will be a lot of changes like th new “goto” feature that break has. ereg was moved to PECL. And also the new Fileinfo from PECL will be integrated as a default extension, for file support since there wasn’t really much mime type detection that would help us in the future.

    Great read,
    Lamonte(owner) @ phpdiscovery.com

  2. Thank you Lamonte

  3. u rock man !

  4. Thanks Sunil.
    Excellent Post!
    You have described PHP 5 feature in a very simply.

Leave a Reply

Top Internet blogs Programming Blogs - Blog Catalog Blog Directory TopOfBlogs Technology blogs Top Blog Topsites List