Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I would like to discuss why is PHP called a structural language? what are the OO concepts that cannot be implemented using PHP?

share|improve this question

migrated from stackoverflow.com Feb 20 '11 at 13:31

This question came from our site for professional and enthusiast programmers.

closed as not constructive by ChrisF Dec 9 '11 at 17:36

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

14  
It's not so much about what "can be implemented using php" (it's turing complete, anything can be implemented in it with enough effort), but rather which principles influenced PHP's design. Of course, if we follow that to its logical conclusion, then PHP certainly isn't a structured programming language, and we'll have to coin a new category... Incompetence-based language doesn't seem like a name that's likely to catch on though.... –  jalf Feb 20 '11 at 12:56
5  
but regardless of what PHP is, it didn't have more than the most rudimentary OOP features until PHP5. Its OOP features are overlaid on top of an old, crufty, sloppy and badly designed structural language. –  jalf Feb 20 '11 at 12:57
    
@Jalf. Outstanding points given –  Awais Qarni Feb 20 '11 at 13:01
2  
PHP is a language? –  Job Feb 21 '11 at 16:50
    
Since PHP5.3, you can add functional. Maybe you can put an AND between theses paradigms instead of an OR ;) –  deadalnix Feb 29 '12 at 17:19

4 Answers 4

up vote 10 down vote accepted

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.

share|improve this answer
    
@vertec good analysis. I think php is also supporting with many methods to manipulate different things –  Awais Qarni Feb 21 '11 at 16:45
    
I'd agree, PHP is object-capable, not object-oriented. OOP in PHP can be ignored, that to me is not the mark of an OO language. –  Gary Willoughby Feb 21 '11 at 21:44
    
+1 for distinguishing, in effect, "supports OOP" vs. "allows OOP". –  JUST MY correct OPINION May 21 '11 at 10:09
    
I would be willing to bet though that as development of PHP continues they we will see PHP become more and more OOP than it currently is... +1 for "object-capable". –  Kenneth Sep 1 '11 at 4:45

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:

  • Class
  • Instance
  • Method
  • Message passing
  • Abstraction
  • Encapsulation
  • Inheritance
  • (Subtype) polymorphism
  • Decoupling

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.

share|improve this answer
1  
@ Martin. Hundred percend agree with you.... You have analyzed in very good manner. I am also of the view that we can implement all concepts of oop in php then why some critics still dont agree to call it as oop based language –  Awais Qarni Feb 21 '11 at 16:08
1  
I fully second that –  Raffael Dec 9 '11 at 17:16

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.

share|improve this answer
    
That's not an answer. Please provide at least a small excerpt from the article (your link may go awol over time). –  Yannis Rizos Nov 16 '11 at 23:37

1) the first paragraph of the wikipedia-artical on structured prog langs says why

2) there are no OO concepts you cannot apply in PHP

share|improve this answer
1  
There are no OO concepts you cannot apply in <any language> –  Raynos Dec 9 '11 at 17:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.