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



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!

{ 71 comments to read ... please submit one more! }

  1. Where did you read “all/most aspects of the language being rooted in objects” as the definitive definition of “object-oriented”? Object-oriented programming is a programming paradigm. It is abstract. It is not concrete. Not all words have concrete definitions.

    “Object-oriented” does not tell you that a language is 99% objects in the same way that me being a “goal-oriented” person doesn’t say my life is 99% goals.

    Additionally, words that make up a phrase shouldn’t be used to determine the meaning –“oriented” around “objects”– this isn’t the same as learning root words. The phrases “slim chance” and “fat chance” mean the same thing, but looking at the words themselves, especially together, there’s no way you could determine this.

    If anything, you should be thinking of an adjective that describes a language as consisting of all/mostly objects, not downsizing a general term to be used on a certain subset of languages. “Prototype-based” means a language is based on prototypes, so why not “object-based”? Oh wait, too late, that already means something else…

    Terminology is and always will be confusing, that’s why if you really want people to understand you, use layman’s terms and concrete terms. Object-capable conveys as little as object-oriented does. You don’t know what data-types (some, all, etc) are objects. You don’t know if it’s objects created from classes, prototypes, cloning, etc…

    Object-oriented is a general term. A concept. An abstraction. It is a word that should NEVER be used when you want to actually talk about the nitty-gritty stuff. If somebody says X language is “object-oriented” or X language is “object-capable,” you know as little as you did before going into that conversation. In fact, if somebody says something is “object-oriented” and stops there without any elaboration, it’s likely a fair assumption that they know jack-diddly-squat.

  2. mgkimsalisawanker

    its obvious mgkimsal is a wanker.

    do you think anybody gives a fuck whether php is oop or not?

    you pompous pretentious fucktard, learn how to talk properly you inbred cocooned cunt face

    you sad pathetic cunt

  3. PHP OOP or not …i love PHP

  4. PHP should be object-oriented, to make easier echoing of html tags with all attributes. Currently it looks like code soup.

  5. You’re a freaking java douche

  6. I wonder if there is any point to using classes in PHP since they are destroyed with each page load. All your objects must be re-instantiated with each page load. Even the singletons right? So you even have to have multiple singletons. The classes must be read in and create their objects with each page load. That seems like it would really slow things down and defeat the purpose of using objects.

  7. Maybe people have incomplete concept of what OOP is.
    Maybe we could say PHP is not completely OOP.
    Maybe we could say PHP “could be” OOP.
    What the heck! What is important is we can solve problems geekely! (may invented word)

  8. By your logic, C++ is not object oriented, and that is plain wrong. Object oriented means the ability to create objects, not being forced to use objects.

  9. Nice POints

  10. @Anonymous: Regardless of the terminology, saying that PHP 5 is object oriented would still be wrong. Your user-defined code can be entirely object oriented but inside your classes and methods you still end up calling PHP’s procedural functions. PHP and its extensions provide only a few “native” classes and methods.
    You can write object oriented code with PHP, but the language and almost all facilities it provides are entirely procedural.

  11. Wow that anonymous guy seems really upset to learn PHP is only object-capable.

  12. I would say that PHP is not an object oriented language, but does have support for object oriented programming.

  13. StackOverFlowSentMeHere

    This post is spam. The comments like wise. According to you guys, object oriented does not exist. I would love to here your views on Javascript.

  14. In PHP :

    Did variable exist as a class member ? No
    Was any class instantiation involved ? No
    Did it work ? Yes
    PHP is NOT object oriented.

  15. @Mark
    The PHP OO programming paradigm is useless if everything your users did required a page load.. you truely are old-school… Perhaps if you could grasp the modern web application development concepts that users visiting your site expect it to be fast, fluid, and real-time.
    If you put any thought into this you would realise your statement is pathetic (however true in a sense).

    PHP OO programming paradigm is still quite useless however its not because of page loads, it is because its scope is per script execution.
    Unless measures are taken, your user actions will execute your PHP per action, and frequently, either by page loads in your ancient interpretation or via client-side scripting that utilises server-side processing such as AJAX calls.

    So I agree that PHP OO programming paradigm is useless if it is the sole consideration.

    But I challenge you to try to code as quickly as I do without using PHP OO programming paradigm model even once in your server-side scripting. I for one cannot do without OO PDO database connections and prepared statements (being a requirement for security) nor can I produce my API coded in PHP without the use of objects.

    If anyone can come up with a solution that will allow Objects to stay alive and be reused during the life-cycle of a visitor to my site, then PHP OO programming paradigm will no longer be considered as useless!

  16. It’s obvious from mgkimsalisawanker comments that PhP is not even close to being OOP and cannot be taken seriously as a solid web-development platform or language. It’s a language for college students who do onjt know any better.

  17. Your definition of ‘object oriented’ -everything is an object – is just: WRONG. Therefore the article is just: USELESS. Following your argumentations, Java wouldn’t be object oriented too as it supports simple data types. Thats totally CRAP!

    Correct is: PHP is a weak typed, interpretend language that supports the procedural programming attempt as well as the object oriented attempt.

    Read about the paradigms if object oriented programming and tell me one that isn’t support by PHP. Yepp! You will tell ‘There is no polymorphism’. But that is not true. True is: The interpreter itself doesn’t support it like e.g. in Java. But because of the weak typing of PHP it is up to the programmer to implement polymorphism – and this is widely used across available API’s –


  18. I cannot agree more. I know C++, java and C# pretty well. I first learned OOP in C++ and picked up Java and C# pretty quickly because these languages follow similar OOP paradigm. Due to the popularity of PHP, I have to learn it to work on projects written in PHP. I find that PHP is a mess in terms of being a OO language. The ‘magic’ methods are a mess. You can use these magic methods to call methods that do not exist in a class? What is this? No other OO language I know of allow this.

    PHP is not a OO language! It is just a pretender.

    Perhaps PHP should have gone the path of C. Build a true OO PHP from scratch and make it PHP++ or PHP#.

  19. Yeah, he’s right. You can create objects like any other programming language. When php was written it had a lot of build-in functions only and there were no build-in classes actually. Now they’re making build-in classes and converting the old-style functions to object-oriented style.

  20. Wow – I found some more comments by people in the ‘pending’ list (there’s > 1500 pending comments, nearly all spam) but I’ll approve them as I find them.

    Can’t believe people are still getting worked up over this post from years ago, but… I basically still stand by what I said.

  21. To be OO, all a language has to do is support inheritence.

{ 0 Pingbacks/Trackbacks }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>