Home > PHP, PHP Tutorials, PHP5 OOPS Tutorials > PHP5 OOPS Tutorial – Introduction to PHP5 OOPS Features

PHP5 OOPS Tutorial – Introduction to PHP5 OOPS Features

November 7th, 2007 admin Leave a comment Go to comments

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

Categories: PHP, PHP Tutorials, PHP5 OOPS Tutorials Tags:

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/sunilb/www.sunilb.com/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php:245) in /home/sunilb/www.sunilb.com/wp-content/plugins/mycaptcha/MyCaptcha.php on line 41

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/sunilb/www.sunilb.com/wp-content/plugins/all-in-one-seo-pack/aioseop.class.php:245) in /home/sunilb/www.sunilb.com/wp-content/plugins/mycaptcha/MyCaptcha.php on line 41
  1. November 14th, 2007 at 09:38 | #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. admin
    November 14th, 2007 at 09:44 | #2

    Thank you Lamonte

  3. rocly s
    February 4th, 2008 at 12:11 | #3

    u rock man !

  4. Pranav Dubey
    September 21st, 2008 at 13:12 | #4

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

  5. Pooja Sharma
    August 27th, 2009 at 13:06 | #5

    This is the short and sweet post.

  6. Pooja Sharma
    August 27th, 2009 at 13:07 | #6

    Php 6 also supports the “go to” statements like to that of C,the previous versions of PHP did not support.

  7. Ajay
    September 8th, 2009 at 11:15 | #7

    Hi, Your throught is nise……..and your tutorials excelent…………….

  8. Greg
    September 8th, 2009 at 19:40 | #8

    There are lots of syntax explanations, but few semantic ones.

    Lots of ‘Write CLASS followed by a squiggly bracket’ but very few explanations of why you want to declare a Class and what it signifies – how you use it.

  9. September 28th, 2009 at 21:55 | #9

    Hey Man
    Nice Posting all things in this blog site.I loved it.
    I am in IT industry from last 2 year and currently working as Software Engineer and now find great tut.
    Thank you for awesome posting.

  10. Atul Rathore
    November 9th, 2009 at 09:53 | #10

    Thank’s sunil for better participation of use full topic and better explanation of every topic.

  11. Kuldip
    February 6th, 2010 at 10:21 | #11

    Amazing tutorial.
    Its very easy to understand.
    Waiting for other OOPS concepts of PHP like
    Inheritance, use of Abstract, etc..

  12. admin
    February 6th, 2010 at 10:28 | #12

    Hi Kuldip,

    Thank you for your appreciation.

    Click this link for other PHP5 tutorials:
    http://www.sunilb.com/php-tutorial

    Regards,
    Sunil

  1. No trackbacks yet.
Enter this code to leave comment (Sorry, but bots get me crazy :) )