eacy to use constructors in php class. when we creating a objects from using the new keyword the constructor function automatically executes
PHP Code:
class Box
{
var width;
var height;
function box($pmWidth,$pmHeight)
{
$this->width =$pmWidth;
$this->height=,$pmHeight;
}
function area()
{
return $this->width*$this->height;
}
}
//This is syntax for Calling of constructor function
$object = new Box(100,100); //The new key word used to create an object
echo “Area of object box:”. $object->area();
output
Area of object box :1000