OOP PHP তে instanceof এবং Constructor

Author: Al-mamun Sarkar Date: 2020-04-18 10:35:54

এই Lesson এ Object-Oriented PHP তে  instanceof এবং Constructor এর ব্যবহার 

 

Constructor:

class Math {

	public $a;
	public $b;
	
	public function __construct($first, $second = 15) {
		$this->a = $first;
		$this->b = $second;
		$this->display();
	}

	public function sum() {
		return $this->a + $this->b;
	}
	public function mul( $c = 2 ) {
		return $this->a * $this->b * $c;
	}
	public function display() {
		echo "Welcome boss <br/>";
	}
}

$foo = new Math(10, 20);
echo $foo->sum();
echo "<br>";
$obj = new Math(30);
echo $obj->sum();
echo "<br>";
echo $obj->mul(3);

 

Instanceof:

require "many_class.php";

$obj = new A();
// $b = new B();

if ( $obj instanceof A ) {
	$obj->welcome();
}