Object-oriented programming is a programming model organized around Object rather than the actions and data rather than logic.
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 ({}).
This is the blueprint of the construction work that is class, and the houses and apartments made by this blueprint are the objects.
<?php class MyClass { // Class properties and methods go here } ?>
In PHP, to see the contents of the class, use var_dump(). The var_dump() function is used to display the structured information (type and value) about one or more variables.
var_dump($obj);
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.
<?php class MyClass { // Class properties and methods go here } $obj = new MyClass; var_dump($obj); ?>
<?php class demo { private $a= "hello rookienerd"; public function display() { echo $this->a; } } $obj = new demo(); $obj->display(); ?>
Output:
<?php class demo { private $a= "hello rookienerd"; public function display() { echo $this->a; } } $obj = new demo(); $obj->display(); var_dump($obj); ?>
Output: