PHP OOP Introduction
Object Oriented Programming is the coolest thing in PHP!
What is Object Oriented Programming?
Object Oriented Programming, also known as OOP is a special way of programming. It is considered to be more powerful and fast for certain tasks than normal way of programming in PHP. OOP helps you to create and manage tasks easily.
Some advantages of OOP:
Easy to manage
Easy to use
Fast and efficient
OOP is harder to understand than normal (procedural) programming. But, if you understand following 4 terms you are almost done!
Methods (or Functions)
In OOP, a task or topic is handled by one class.
What is a Class?
The first term we find in OOP is class. Class is a blueprint. It is a piece of code describing how to manage a topic or task in the way we want.
For instance, a blueprint of a house is like a class. You can built more than one house from the same plan. In the same way you can create more Objects from a class.
What is an Object?
Object is an instance of a class. It's a house built from the blueprint.
Each house can have its own color, floor tiles, home equipments and more. In the same way, different objects can have different properties.
What are Properties?
Properties are variables of an object. They are the values associated with the object. They describes the appearance of the Object.
Properties can be added, changed, removed. Some can also be read-only.
Color is a property of our house.
We can also perform actions on our house (like changing the color).
What are Methods?
Methods are actions that can be performed on Objects. Changing the color of my house is a method performed on my house object.
Create the blueprint (Class)
Create my house from the blueprint (Object)
Add color, width, height, floor tiles, etc. to the house (Properties)
Change the color when you need to change it (Methods)
In next tutorials, we will learn how to use these things in PHP.