Constructor
<?php
class Person
{
public $name, $age;
function show()
{
echo $this -> name . " " . $this -> age . "<br>";
}
function __construct($name = "No value", $age = 30)
{
$this -> name = $name;
$this -> age = $age;
}
}
$p1 = new Person();
$p2 = new Person("Yahoo Baba", 20);
$p3 = new Person("Ram Kumar", 50);
$p1 -> show();
$p2 -> show();
$p3 -> show();
// OUTPUT:
//No value 30
// Yahoo Baba 20
// Ram Kumar 50
?>
Comments
Post a Comment