Instance of

<?php
	class employee {
		private $empId;
		private $name;

		function __construct($empId,$name) {
			$this->name = $empId;
			$this->age = $name;
		}
	}
	
	$emp = new employee("EP20", "Ajoy");

	/* Check the object is a instance of the class or not using 'instanceof' */
	if($emp instanceof employee)
		echo "\$emp is a object of employee class - instanceof<br />";
		
	/* Check the object is a instance of the class or not using 'is_a' */
	if(is_a($emp, employee))
		echo "\$emp is a object of employee class - is_a()";
?>


/* Output */
$emp is a object of employee class - instanceof

$emp is a object of employee class - is_a()

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!