PHP - What is OOP?

From PHP5, you can rewrite PHP code in object-focused style.

Object-oriented planning is quick and easy to use.


PHP What is OOP?

OOP stands for Object-Oriented Programming.

Process planning is about writing processes or tasks that perform tasks in data, while object-focused planning is about creating objects that contain both data and functions.

Object-oriented planning has fewer benefits than process planning:

  • OOP is fast and easy to use
  • OOP provides a clear framework for programs
  • OOP helps keep PHP code Dry "Do not repeat", and makes the code easy to save, correct and debug.
  • OOP makes it possible to create fully reusable applications with minimal code and short upgrade time

Tip: The "Do Not Repeat" (DRY) policy is about reducing code duplication. You have to extract the standard codes in the app, and put them in one place and reuse them instead of repeating them.


PHP - What are Classes and Objects?

Classes and objects are two main elements of an object-focused program.

Look at the following picture to see the difference between class and objects:

class

Fruit

objects

Apple

Banana

Mango

Another example:

class

Car

objects

Volvo

Audi

Toyota

So, the class is a model of things, and the object is a model of the class.

When each item is created, it inherits all the features and behaviors in the classroom, but each item will have a different set of properties.

See the following chapters to learn more about OOP.