Member-only story

OOPS concepts in PHP with real-time examples

Bipsmedium
3 min readAug 12, 2022

--

OOPS means object-oriented programming. As we all know object-oriented programming is better than procedural programming. In procedural programming, we can write functions that contain operations on data but in object-oriented programming, we can write functions that contain both data and objects. It is based on classes and objects. Let us discuss the oops concepts in PHP with real-time examples.

Also read, How to display data from database in PHP

Class and object in PHP

  • A class is like the name of an entity such as fruit, vehicles, smartphones, men, lady, father, son baby, etc.
  • It is declared using the class keyword with curly braces. All the codes, functions, and blocks of statements are written inside the class name.
  • A class works as a template for an object and an object is an instance of a class. A class can create multiple objects.
  • When an object is created, it inherits all the properties and methods of its class but the values of the properties should be different.

How to create an object in PHP

An object is created with the help of a new keyword as shown below

$car = new Car();

whereas $car is an object reference variable of the parent class Car. By using this $car object, we can call the values defined in the methods of the parent class Car.

--

--

Bipsmedium
Bipsmedium

Written by Bipsmedium

Hi, This is Biplab and I am a PHP laravel developer and other open source technologies. I am here to share my experience with the community.

No responses yet