Thu Jun 04 2020

Instance of

PHP Scripting989 views

File Name: instance-of.php

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

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