Thu Jun 04 2020
Instance of
PHP Scripting988 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:
instance of and is_a
Author:Geekboots