PHP OOP Introduction
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 the 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
- Prevents repetition
- Fast and efficient
OOP is harder to understand compared to other programming techniques. But, if you understand the 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. A 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 class is like a blueprint of a house.
You can build more than one house from a blueprint. In the same way, you can create more Objects from a class.
What is an Object?
An Object is an instance of a class. It is like a house built from the blueprint. You can build more than one object from a class like creating multiple houses from a blueprint.
Each house can have its own color, floor tiles, home equipment 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 describe 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 are performed on Objects. Changing the color of my house is a method performed on my house object.
What we learned about OOP
- 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)
About the PHP Object Oriented Programming Tutorial for Beginners
This tutorial has been written for beginners in Object-Oriented Programming. Each chapter is described with graphical illustrations and example codes. Therefore, you will understand and remember more.
Also, this tutorial is designed not only to gain your knowledge on Object-Oriented programming but also to make a sense in your mind where OOP is useful and where we should use it and not.
In the next chapters, we will learn how to use the above concepts in a practical way.