phpoopprocedural-programmingprocedural

simple explanation PHP OOP vs Procedural?


I would like to learn PHP and want to get an Idea about OOP and Procedural. I read some other blogs and tutorials about OOP vs Procedural but I still can't understand the approach.

OOP vs Procedural

  1. Which I should learn?
  2. What is the difference in code? What are the effects?
  3. How can a PHP framework help in OOP aproach? (I would like to learn CodeIgniter)
  4. Does procedural need a Framework?

I really want to know the code difference of the both, my understanding of OOP is you create a class like and it can be access. (I don't know if that is correct).


Solution

  • Background: You asked for a "simple explanation" which suggests:

    1. You want a no-nonsense overview without jargon
    2. You want something that will help you learn from the beginning
    3. You have discovered that no two people ever answer the question the same way, and it's confusing. That's the reason you are here asking for a simple explanation. Yes?

    Short No-Jargon Answer:

    1. Many introductory explanations jump quickly into "OOP real world" examples. Those can tend to confuse more than help, so feel free to ignore that for now.
    2. You can think of source code simply as "chunks" of functionality, that just happen to be saved to individual files.
    3. There are different ways of organizing those "chunks"; depending on things like conventions of the programming language, the background and training of the developer(s), or just plain old personal preference.
    4. OOP and Procedural programming are simply two main, generally-recognized methodologies, for how to organize and arrange those "chunks" of code.

    Long No-Jargon Answer:

    Procedural vs OOP is just one aspect of a fundamental issue of computer programming: how to make your code easy to understand and a piece of cake to professionally maintain. You can actually write "Procedural" code that follows some of the principles of OOP, so the two are not necessarily opposites.

    Your understanding will really grow once you learn other object-oriented programming languages, among which, PHP is a "new kid on the block".

    Here is a quick overview of what you will learn as you build experience:

    See also