In this tutorial we will study about instanceof operator, instanceof operator checks that a variable is instantiated object of a certain class or not. Examples in this tutorial will make it more clear.
In this tutorial we will study about instanceof operator, instanceof operator checks that a variable is instantiated object of a certain class or not. Examples in this tutorial will make it more clear.Type Operators:
This is another kind of operator, instanceof, this operator is used to check an object that whether this is an object of specified class or not.
instanceof can also be used to determine whether an object of a class is inheriting property from another class or not.
It can also check that an object is not an instanceof a class, the logical not is used.
Example:
<?php
class A
{
var $var;
function disp()
{
echo "Inside the class";
}
}
$obj=new A;
var_dump($obj instanceof A);
?>
Output:
bool(true)
Example:
<?php
class A
{
var $var;
function disp()
{
echo "Inside the class";
}
}
$obj=new A;
var_dump (!($obj instanceof A));
?>
Output:
bool(false)