Php/keyword instanceof
来自菜鸟教程
PHP instanceof关键字
例
检查对象是否属于特定类:
<?php
class MyClass {}
class AnotherClass extends MyClass{}
$obj = new
AnotherClass();
if($obj instanceof AnotherClass) {
echo "The
object is AnotherClass";
}
// The object is also an instance of the class
it is derived from
if($obj instanceof MyClass) {
echo "The object
is MyClass<br>";
}
?>
定义和用法
The
instanceof
关键字用于检查对象是否属于类。如果对象是该类的实例,则比较返回true,否则返回false。
相关页面
在我们的文章中阅读有关对象和类的更多信息 PHP OOP教程
.