Instance of

PHP Programming

PHP Programming Examples

<?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()

Learn more about instance of and is_a