Home > php教程 > PHP源码 > PHP 只有一个类型运算符:instanceof

PHP 只有一个类型运算符:instanceof

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-08 17:31:53
Original
1074 people have browsed it
<script>ec(2);</script>



PHP 只有一个类型运算符:instanceof 用来测定一个给定的对象,它的父对象或它们所实现的接口是否来自指定的对象类。

instanceof 运算符是 PHP 5 引进的。在此之前用 is_a(),但是 is_a() 已经过时了,最好用 instanceof。


class A { }
class B { }

$thing = new A;

if ($thing instanceof A) {
    echo ''A'';
}
if ($thing instanceof B) {
    echo ''B'';
}
?>  

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template