PHP - Object Oriented Programming

PHP introduced object-oriented programming features since version 5.0. Object-Oriented programming is one of the most popular programming paradigms based on the concept of objects and classes.

PHP OOP allows you to structure a complex application into a simpler and more maintainable structure.

Class:

A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object.

In PHP, declare a class using the class keyword, followed by the name of the class and a set of curly braces ({}).

class MyClass  

    {  

        // Class properties and methods go here  

    }  

?>  

Object:

A class defines an individual instance of the data structure. We define a class once and then make many objects that belong to it. Objects are also known as an instance.

An object is something that can perform a set of related activities.

class MyClass  

{  

        // Class properties and methods go here  

}  

$obj = new MyClass;  

var_dump($obj);  

?>