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.