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
- Which I should learn?
- What is the difference in code? What are the effects?
- How can a PHP framework help in OOP aproach? (I would like to learn CodeIgniter)
- 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).
Background: You asked for a "simple explanation" which suggests:
Short No-Jargon Answer:
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:
You can write PHP source code that does useful tasks
You can organize useful tasks into "chunks" of code
You can think of "chunks" of code independently of the individual files where they are saved
Sometimes those "chunks" of code will behave differently based on parameters you pass in
Chunks of code that accept parameters are called "Functions"
Functions can be "chunked" together, and there are different ways of doing this:
OOP is a special way of "chunking" Functions together into a "Class"
A Class is just another level of "chunking" code together so that you can treat it as a unified whole
A Class can be thought of as a "chunking" of methods and properties
A Class is useful because it allows you to organize your code at a very high level in a way that makes it easy for you to understand, use, and maintain.
When someone has written a lot of functions, and organized them into a lot of Classes, and gotten those to work together in some cool way, they package the whole thing together and call it a "Framework".
A Framework is just the next-highest level of "chunking" (including coding style and conventions) that one or more people agree on because they like the way the code is organized and it suits their working style, preferences, values, plans for world domination, etc.