I could noot understand any benifits in PHP programming.We can have access methods,abstraction,inheritance. But I can't understand the real benefits while programming in OOP.
-
This question is too broad. There are entire books written on the subject. For me, the main 'benefit' of OO is to be able to group "things" into self-contained packages in a uniform manner *that supports polymorphism*; but most everything except for polymorphism (which require dispatch look rules) can be 'easily obtained' even in a procedural style. Consider the mysqli procedural vs OO API as an example - both "take" an object to work on. The main difference here is procedural API 'locks onto' the implementing methods. – user2864740 Aug 21 '15 at 04:54
-
Your question is duplicate of this [question](http://stackoverflow.com/questions/552336/oop-vs-functional-programming-vs-procedural) – Шыназ Алиш Aug 21 '15 at 04:56
-
All in all, Easy updation and maintenance, Easy debugging for finding errors, Better Readability ! – Hytool Aug 21 '15 at 05:00
-
@user2864740 This is not duplicate ques, I am asking this question for PHP, a Interpreting language – Shivin narayan Aug 21 '15 at 05:00
-
@Shivinnarayan It doesn't make a difference; OO is OO (or really, *some variation of OO*). C++, PHP, Java, Ruby, JavaScript, SmallTalk, Eiffel.. whatever. But the same 'difference' remains: some form of runtime type polymorphism and some notion of an object 'from a template'. This question is Too Broad (see [the general Wikipedia entries](https://en.wikipedia.org/wiki/Object-oriented_programming)). Now, if there is a *specific* question about OO - or the implementation of such - then, such might make a good question. – user2864740 Aug 21 '15 at 05:04
-
@user2864740 This is not what I am looking for... – Shivin narayan Aug 21 '15 at 05:18
-
As it is written, the answer being 'looked for' is Too Broad. If this is not believed to be the case, please try to make the intent more clear. The ['Help' section](http://stackoverflow.com/help) of the site provides advice on how to write a Good Question; and it explains which questions are Not Suitable for SO, and why. (Since there is already a similar - and arguably Too Broad, albeit possible less Opinion Based - question, then voting for it is as duplicate is also a suitable response.) – user2864740 Aug 21 '15 at 05:24
2 Answers
Object oriented programming is about organizing code in another way than before. It is an extension of procedural programming, and it is about hiding data (encapsulation) and avoiding a global scope. It is about extending functions by "borrowing" their blueprints without actually affecting the original code (inheritance). And it is about overriding functions without affecting the original code (polymorphism).
A funny thing to think about is that many object oriented programming languages are developed in a pure procedural programming language. PHP for example is developed in C and the object oriented features of PHP is a result of a pure procedural implementation.

- 63
- 6
-
I think you are saying about features of OOP, But I wanted to know that the real benefits of PHP OOP over procedure programming.. – Shivin narayan Aug 21 '15 at 06:25
There are a lot of books written on oop. It will really benefit for those who properly organize their code. If you have proper oop knowledge,then you will be able do following:
Re-useability
Inheritance
Polymorphism
Now come to the main point in pure technical way,which will help you more.
If you have done a project having design pattern MVC, you have noticed: When ever,you make a model or controller you have inherit it to base class. That mean, you are getting benefit of Inheritance as well as Re-useability as you have not written same code again and again.
You have once make a connection to database and use in each model as well as query execution from the same function.
You might have some function having different behavior, i mean same name but react differently. For example a function can accept different number of argument and then return data accordingly (Polymorphism).

- 1
- 1

- 570
- 2
- 10
- 20