<?php class Bappy { private $val; public function __construct() { echo 'The class"', __CLASS__, '" is Construct.'; echo "<br>"; } public function __destruct() { echo "<br>"; echo 'The class"', __CLASS__, '" is destruct.'; } public function setVal($val1, $val2) { $this->val = $val1 + $val2; } public function getVal() { return $this->val; } } $myClass = new Bappy(); $myClass->setVal(5, 7); echo $myClass->getVal();
<?php class Bappy { private $val; public function __construct() { echo 'The class"', __CLASS__, '" is Construct.'; echo "<br>"; } public function __destruct() { echo "<br>"; echo 'The class"', __CLASS__, '" is destruct.'; } public function setVal($val1, $val2) { $this->val = $val1 + $val2; } public function getVal() { return $this->val; } } $myClass = new Bappy(); $myClass->setVal(5, 7); echo $myClass->getVal(); unset($myClass); echo "<br>End of file";
class Bappy { public $val; public function __construct() { echo 'The class"', __CLASS__, '" is Construct.'; echo "<br>"; } public function __toString() { return $this->getVal(); } public function __destruct() { echo "<br>"; echo 'The class"', __CLASS__, '" is destruct.'; } public function setVal($val1) { $this->val = $val1; } public function getVal() { return $this->val; } } $myClass = new Bappy(); $myClass->setVal("I am Bappy"); echo $myClass; unset($myClass); echo "<br>End of file";
<?php class Bappy { private $val; public function setVal($val1, $val2) { $this->val = $val1 + $val2; } public function getVal() { return $this->val; } } $myClass = new Bappy(); $myClass1 = new Bappy(); $myClass->setVal(5, 6); echo $myClass->getVal(); echo "<br>"; $myClass1->setVal(45, 5); echo $myClass1->getVal();