PHP is not object oriented!

Argh!  PHP is *NOT* “object oriented!

Goodness.  I like PHP.  I use it a lot.  I’ve been using it since early 1996.  I’m Zend Certified, have done billion dollar ecommerce projects in PHP, and like to think I know a little bit about PHP.

It is *NOT* “object oriented”.  I wish people would quit saying it.  Perhaps there’s a need to impress non PHP people, or to try to get across the idea that PHP supports objects.  Maybe that’s fair, but I don’t think so.

I remember talking with people in 2004 about PHP5.  They were using it in beta, and “loved” how it was “object oriented”.  I asked why they were using PHP5 in production when it wasn’t even released yet, and it was “PHP4 doesn’t support objects”.

As my wife would say (if she cared about PHP at all) – “Bollocks”.

Yes, we’re years in to PHP5, but I still come across people who state that “PHP is object oriented” or “Since version 5, PHP is object oriented”. 

DEAD.

WRONG.

Look at the words “object oriented”.  Is the language really “oriented” around or towards “objects”?  Abso-smurf-ly not.

Groovy is object oriented.  Pretty much everything in the language is an object or can be treated like one (objects, functions, “primitives”, etc.)

Ruby is object oriented.  I’ve not done much with it, but as far as I can tell, everything is an object (numbers, etc.).

Java – again, with limited exceptions, everything is an object. 

PHP – very few built-in things are objects (dir?).  The SPL is perhaps making an attempt in that direction, but they’re not looking to replace PHP, only be an adjunct.  Strings, arrays, numbers – nothing is an object, nor can it be treated as such.

So, why do we continue to say “object oriented”?  I don’t.  I say “object capable”.  I get weird looks, and occasionally some reactions that are uncalled for, but I still maintain – PHP is not “object oriented”.  And likely it shouldn’t be.  Given that we’ve come this far without it, overhauling PHP so that everything is an object should only be done at a major version.  PHP6 is not that version, so we’ll have years more before/if we ever see a true “object oriented” PHP.

But that doesn’t matter.  Revel in the fact that PHP is a hybrid that supports object-based development when necessary, but allows you the flexibility to be procedural when the time is right.  Wear it as a badge of honor.  But don’t cop out and try to claim that PHP is “object oriented” when it’s not.

*Arguably* one could say PHP permits “object oriented” development, to the extent that one orients their development around objects and thinking of objects.  Possibly fair point, but it’s an niche distinctions, and one which likely few people really *mean* when they say “PHP is object oriented”.  What people really mean when they say “PHP is object oriented” is “PHP is object capable”.  So just say that instead.

Over and out…


I'm currently working on a book for web freelancers, covering everything you need to know to get started or just get better. Want to stay updated? Sign up for my mailing list to get updates when the book is ready to be released!

Web Developer Freelancing Handbook

Be Sociable, Share!

Leave a Reply