Class is a user-defined data type that has properties and methods and the object is the instance of the class. In this lesson, I will show you how to create a class and object of a class.
class ClassName {
// codes for the class
}
class Vehicle
{
public $name;
function setName($name)
{
$this->name = $name;
}
function display()
{
echo "Vehicle Name is : {$this->name} <br/>";
}
public function getVehicleName()
{
return $this->name;
}
}
$obj = new Vehicle();
$obj->name = "Car";
$obj->display();
print($obj->getVehicleName());