Constructor used in object oriented language for allocate
space while creating object. A constructor also helps initialize a variable
while declaring.
Every object oriented language built in support for
programming. PHP is also a server side script and object oriented language. So
should know how can you use constructor is elaborate in following example.
<?php
class Foo
{
private $roll, $name, $city;
function __construct($roll, $name, $city)
{
$this->roll = $roll;