I would like to discuss why is PHP called a structural language? what are the OO concepts that cannot be implemented using PHP?
I consider PHP language to be object-capable, not object-oriented. That's because most of the built-in constructs are not object-oriented. Take an array or a string for example. In object oriented language, you'd use it's methods to manipulate it. In fully fledged object-oriented language everything is an object.
On the other hand PHP is object-capable, you can write code, that will be OOP. Instead of using for example normal arrays, you can use data structures from SPL, which actually are OOP. The only problem with that is, it's an extension, not a part of the language itself.
Classification of programming languages is an art as most languages falls in many categories. In this case it's simple enough though. PHP is an imperative OO language, like C++. That is, you can select to use objects and classes if you like, but you don't have to.
As regards to what you can and cannot do with objects in PHP, I don't really see anything missing. But "missing" is a relative term here, as some OO languages have more features and others less. For instance, some consider language-supported properties to be a hallmark of OO, something that is lacking in both Java and PHP. Still Java is undoubtedly in the OO camp.
Judging from Wikipedia, the fundamental concepts in OO is:
- Message passing
- (Subtype) polymorphism
All this is part of PHP.
On a personal note, I haven't found anything in PHPs OO implementation that is lacking. There is lots of stuff in PHP that is seriously flawed, inconsistent and just weird, but that is another issue. It's OO constructs are good enough to be called complete.
I wrote an article which might help to clarify this issue!
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.