Why learn OOP in PHP – another take.

php logo

Why learn OOP in PHP – another take.

For people new to OOP and are comfortable with ‘classic’ procedural php, you may be wondering why should you even bother to learn object oriented concepts … why go through the trouble?

The PHP world:

PHP is moving in an OOP direction. For example, many important PHP extensions like PEAR and Smarty are OO based. So, to really understand and use these frameworks properly, you need to understand object oriented PHP.

The functional/practical advantages:

For smaller projects, using object oriented PHP may be overkill. That said, object oriented PHP really begins to shine as the project becomes more complex, and when you have more than one person doing the programming.

For example:

If you find that you have say 10-20 or more functions and you find that some of the functions are doing similar things … it is time to consider packaging things up into objects and using OOP.

OOP and your career as a programmer:

OOP is the modern way of software development and all the major languages (Java, PERL, PHP, C#, Ruby) use this method of programming. As a software developer/programmer, it only makes sense (in terms of career,) to keep your skills up-to-date.

Besides making you a more valuable PHP coder, understanding OOP in PHP will give you knowledge (OOP knowledge,) that you will be able to take with you into other languages.

… When you learn OOP in PHP, you’ll learn object oriented programming for any OO based language.

You will find with time that creating OOP based PHP projects, will just make your life as a programmer much easier. As an added bonus, soon you will develop your own collection of reusable objects, which you will be able to leverage in other projects.

Finally, You will also find that OOP based PHP is much easier to maintain and update.

OOP Challenges:

OO PHP does present some challenges when you first start out because you’ll need to learn to think about your PHP projects in a different way: you will need to conceptualise the project in terms of objects.

More details …

One common way of starting an object-oriented project is to start by drawing up simple diagrams of your objects. As you begin to work with object diagrams, you will find that they help make developing OOP based PHP projects much easier.

Here are a few tips about drawing object-diagrams:

· Use a paper and pencil
· Draw boxes to represent each object
· In those boxes, list your methods and your properties
· Use arrows and lines between boxes to denote relationships (parent – child) between objects.

So if you have been sitting on the fence waiting to jump into OO PHP, now is as good time as any to get started.

Stefan Mischook

www.killerphp.com
www.killersites.com


This entry was posted on Friday, September 7th, 2007 at 8:48 am and is filed under Beginners PHP Articles, Object Oriented PHP. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

3 Responses to “Why learn OOP in PHP – another take.”

  1. Stefan Mischook’s Blog: Why learn OOP in PHP – another take…

  2. […] Stefan Mischook has posted another take on why he thinks PHP developers should learn object-oriented programming: For people new to OOP and are comfortable with ‘classic’ procedural php, you may be wondering why should you even bother to learn object oriented concepts…why go through the trouble? […]

  3. Michael says:

    To reach real OO wisdom you have to learn Smalltalk succeeders and Smalltalk itself. Java and Ruby have different approaches here.

    PHP OO support is still too simplified to understand the whole thing.

    Here are some Ruby idioms from famous ThoughtWorker:
    http://memeagora.blogspot.com/2007/09/ruby-matters-place-to-put-your-stuff.html

Created By Stefan Mischook  |  Top of page  go to top of page