PHP Objects; PHP Supports Objects but is NOT Object Oriented

There is a big dilemma and misunderstanding between programmers regarding the object orientation of PHP. I have read a lot of forums and books on this subject, and I’d like to clarify it once and for all.

Before actually providing my opinion, let me be really clear in something; I like PHP, I am PHP Certified, and I use it every day for Optimum7, a pretty innovative company that I work for as Senior Programmer, and if this would help… “I always program in php thinking in objects”. I can’t do it differently after programming for more than 9 years in C#.Net, where “everything is an object”. But once again, PHP is not Object Oriented!

Let’s make an analogy to clarify this. We can all run, right? But, we are not all “made” for running. The fact that we have the ability to run does not mean we are made for that specific action. Carl Lewis (the fastest runner in his day) was made to run from the beginning; he trained for it; he sacrificed everything to achieve at the highest level. We all know him as “the runner”. He was made for it and he developed it to the max!

What about Technical Considerations?

It is said that in order for a programming language to be Object Oriented, it needs to support at least these three basic concepts: Encapsulation, Inheritance and Polymorphism. However, PHP doesn’t exactly contain a ‘full’ complement of these three things, so these words don’t exactly apply to PHP like they do to other languages like C# for instance.

Here are just 3 of the thousands of reasons that clearly illustrate that PHP is not Object Oriented;

1)      It does not support casting of objects from one class to another.

2)      It was not developed to be Object Oriented i.e. thousands of functions do not belong to any object.

3)      “A new PHP” Project (Zend Framework) was created to make PHP, Object Oriented.

Object Oriented Programming is more than a commercial phrase; it is a syntax or API Application Programming. It is a manner of thinking about the problem in a more productive model. As Tom Archer said: “In a truly Object Oriented language, every entity is expressed through the concept of objects. The objects are the main and unique idea behind the concept of Object Oriented”… As I say: Not everything that appears is!

Carl Lewis was made for running, not swimming.  PHP supports objects but was not designed to be object-oriented.

September 1, 2011

Written by Julian Beaujardin

Julian is our go-to person when we need to develop a new SEO tool. He makes our team’s great ideas a reality. Julian developed our very own article submission and tracking software, backlinks monitor and blog search. He is also instrumental in the resolution of clients’ programming issues.

This entry was posted in Web Development and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. rock
    Posted September 1, 2011 at 9:13 am | Permalink

    wow, the “technical” reasons (3 out of the thousands you say) are just a funny atempt to make a statement that is dead wrong. Since when: “It was not developed to be Object Oriented i.e. thousands of functions do not belong to any object.” says anything about the OOP features of a language.

    ““A new PHP” Project (Zend Framework) was created to make PHP, Object Oriented.” – what ? tell me you’re joking. The Zend framework does not provide OOP features – it uses them.

    In PHP 5 “Encapsulation, Inheritance and Polymorphism.” are there.

    “In a truly Object Oriented language, every entity is expressed through the concept of objects. The objects are the main and unique idea behind the concept of Object Oriented” – following that reason Java is not OOP right ? And if not even Java is OOP what is ?

  2. julian
    Posted September 1, 2011 at 11:32 am | Permalink

    Well, aside from what you call a funny attempt to make a “dead wrong” statement, what I meant to convey was that just because PHP supports objects does not mean it was developed with objects in mind.
    And from the beginning—yes, since the exact same moment it was designed–PHP was NOT developed to be Object Oriented. Let me take your words…”In php5…are there”. Really? What about previous versions? Did they support it? Why not, if it was developed to be OO?

    As one of my friends said:
    “ PHP started as a “top down” language (very much like the original days of MS Basic), it then moved into more of a procedural language as more experienced programmers got their hands on it. These days you have very good programmers who understand Object Orientation and they are digging into PHP and helping it move into the Object Orientation world”

    On the other hand, I have been trying something like this in PHP, but still without success!…even with “version5”

    $a = new int(); // Let’s assume that “int” is a PHP Primitive Type. (Integer)
    $a->whateverProperty = any integer value;

    Is this possible in PHP? Is it possible that Primitive Types are also objects? Is this so hard?

    Well…it is when it was not created from the beginning to be used in this way!

    Java is Object Oriented, no one doubts that, but it was created from the beginning to be OO, even since the first version!
    Regarding…”if not even Java is OOP what is”… well, C# and .Net Languages! They over passed Java on this!

    I used to say to my friends: The only thing PHP has from a “true” language is the semicolon (;) at the end of the statement, but of course I am just kidding!

  3. Neo
    Posted May 2, 2012 at 6:20 am | Permalink

    My apologies for commenting late on this, but I am also sick of people insisting PHP is OO. My definition of an OO language … “any language capable of implementing the basic OO design patterns”. Very few OO design patterns can be implemented in PHP.

    It seems everyone who has whiped up a web page is suddenly a computer science expert. If you don’t need OO design patterns, don’t use them because you must know more than every other programmer that has ever solved a problem before.

    If you want to represent yourself as a professional developer, don’t show your ignorance by claiming PHP is anything like an OO language.

Post a Comment

Your email is never published nor shared. 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>