instanceof php
instdnceof php5 的一个新成员
功能: 使用这个关键字可以确定一个对象是否是类的实例,是否是累的子类 ,还是实现了某个特定的接口。
<?php class A{} class B{} class ncccc extends B{} $a = new A(); $b = new B(); $vvv = new ncccc(); $test1 = ($a instanceof A); $test = ($vvv instanceof b); if( $test1 ){ echo " is class A object"; } else{ echo " not is class A object"; } echo "<br>"; if( $test ){ echo " is ok "; } else{ echo " shibai "; }
结果:
is class A object
is ok