How to implement the parameterized constructor using __construct() in PHP | PHP program
Jan 24, 2022
PHP,
1496 Views
How to implement the parameterized constructor using __construct() in PHP | PHP program
How to implement the parameterized constructor using __construct() in PHP | PHP program
we will create a class with data members and implement a parameterized constructor using __construct() to initialize data members.
<?php
class Sample
{
private $num1;
private $num2;
public function __construct($n1, $n2)
{
$this->num1 = $n1;
$this->num2 = $n2;
}
public function PrintValues()
{
echo "Num1: " . $this->num1 . "<br>";
echo "Num2: " . $this->num2 . "<br>";
}
}
$S = new Sample(10, 20);
$S->PrintValues();
?>


