php is instance of code example
Example 1: php instanceof
<?php
$obj = new A();
if ($obj instanceof A) {
echo 'A';
}
?>
Example 2: how work instanceof php method
class MyClass {
}
$o1 = new MyClass();
$o2 = new MyClass();
$name = 'MyClass';
$a = $o1 instanceof MyClass;
$a = $o1 instanceof $name;
$a = $o1 instanceof $o2;
$b = 'b';
$a = $o1 instanceof 'MyClass';
$a = false instanceof MyClass;
$a = $b instanceof MyClass;
Example 3: php instanceof
<?php
class MyClass {}
class AnotherClass extends MyClass{}
$obj = new AnotherClass();
if($obj instanceof AnotherClass) {
echo "The object is AnotherClass";
}
if($obj instanceof MyClass) {
echo "The object is MyClass<br>";
}
?>