PHP What is OOP

This PHP OOP tutorial helps you learn the methodology of programming any application.

As computer scientists discovered more and more programming languages, the ways to write programs also changed. As a result, the conceptualization, methodology, and algorithms evolved over the years. Today, a prevalent method of programming any application is Object Oriented Programming.

PHP is an Object Oriented Programming language. In this tutorial, we will learn about PHP's features that support or enable it to become an Object-oriented programming language. So, let's try to understand Object Oriented Programming (or OOP) and its concepts.

 

What is Object Oriented Programming?

Object Oriented programming or OOP is a programming style associated with the concept of Class, Objects, and various other concepts revolving around class and objects, such as Polymorphism, Inheritance, Encapsulation, Abstraction, etc.

OOP is designed to enable people to focus on an object while programming and not the procedure. Anything we see around us can be this object. It can be a chair (portrayed by size, material, cost, etc.), a human (that has some properties such as - name, address, DOB, and so on), a school (depicted by student strength, place, results), etc.

OOP involves dealing with an object, performing operations on it, using its methods and variables, etc.

 

Concepts of OOP

 

Class

Here a Human Being can be taken as a class. The blueprint of any functional entity is a class. The class defines its properties and its functions. Similar to Human beings, who have body parts and perform various actions.


Inheritance

Now let's consider HumanBeing as a class, having properties like eyes, legs, hands, etc., and performing functions such as talking, walking, seeing, eating, etc. Although males and females are also classes, most of the functions and properties are still included in HumanBeing; hence, everything can be inherited from class HumanBeing by utilizing the Inheritance concept.


Objects

My name is Justin, and I am an instance/object of class Male. When Human Being, Male or Female, are said, we mean a kind, your friend, me, you, we; are the forms of these classes. Human beings have a physical existence, and a class is a logical definition. We are the objects.


Abstraction

It means displaying only the required things to the outside world and hiding the details. We continue with the example, Human beings can walk, talk, eat, and hear, but the details are hidden from the outside world; our skin is the Abstraction factor in us, and hides are internal mechanisms.


Encapsulation

Our legs and hands are binding to help us walk and hold things, respectively. Encapsulation is known as the binding of the properties to functions.


Polymorphism

This concept allows us to redefine the way something works, either by changing how it is done or by changing the parts utilizing which it is done. There are different terms for both the ways.