Type Operators instanceof is used to determine whether a PHP variable is an instantiated object of a certain class/a class that implements an interface
w
0-instanceof is used to determine whether a PHP variable is an instantiated object of a certain class
1-instanceof can also be used to determine whether a variable is an instantiated object of a class that inherits from a parent class
2-Lastly, instanceof can also be used to determine whether a variable is an instantiated object of a class that implements an interface
http://php.net/manual/en/language.operators.type.php
http://php.net/manual/zh/language.operators.type.php
类型运算符
instanceof 用于确定一个 PHP 变量是否属于某一类 class 的实例
instanceof 也可用来确定一个变量是不是继承自某一父类的子类的实例
最后,instanceof也可用于确定一个变量是不是实现了某个接口的对象的实例
<?php interface MyInterface
{
} class MyClass implements MyInterface
{
} $a = new MyClass; var_dump($a instanceof MyClass);
var_dump($a instanceof MyInterface);
bool(true) bool(true)
<?php interface MyInterface
{
} class MyClass implements MyInterface
{
} $a = new MyClass;
$b = new MyClass;
$c = 'MyClass';
$d = 'NotMyClass'; var_dump($a instanceof $b); // $b is an object of class MyClass
var_dump($a instanceof $c); // $c is a string 'MyClass'
var_dump($a instanceof $d); // $d is a string 'NotMyClass'
bool(true) bool(true) bool(false)
instanceof does not throw any error if the variable being tested is not an object, it simply returns FALSE. Constants, however, are not allowed.
如果被检测的变量不是对象,instanceof 并不发出任何错误信息而是返回 FALSE。不允许用来检测常量。
<?php
$a = 1;
$b = NULL;
$c = imagecreate(5, 5);
var_dump($a instanceof stdClass); // $a is an integer
var_dump($b instanceof stdClass); // $b is NULL
var_dump($c instanceof stdClass); // $c is a resource
var_dump(FALSE instanceof stdClass);
bool(false) bool(false) bool(false)
Type Operators instanceof is used to determine whether a PHP variable is an instantiated object of a certain class/a class that implements an interface的更多相关文章
- type 、instanceof、in 和 hasOwnproperty
typeof可以检测的类型有:string.number.boolean.undefined.不可以用typeof检测null typeof也可以用来检测function,但是在IE8及跟早的浏览器中 ...
- java关键字extends(继承)、Supe(父类引用空间)、 This(方法调用者对象)、Instanceof(实例类型-判断对象是否属于某个类)、final(最终)、abstract(抽象) 、interface(接口)0
java 继承使用关键字extends 继承的作用:减少代码量,优化代码 继承的使用注意点: 1子类不能继承父类的私有变量 2.子类不能继承父类的构造方法 3.子类在调用自己的构造方法时 会默认调 ...
- Jetty - Container源码分析
1. 描述 Container提供管理bean的能力. 基于Jetty-9.4.8.v20171121. 1.1 API public interface Container { // 增加一个bea ...
- golang 自定义类型的排序sort
sort包中提供了很多排序算法,对自定义类型进行排序时,只需要实现sort的Interface即可,包括: func Len() int {... } func Swap(i, j int) {... ...
- 23 The Laws of Reflection 反射定律:反射包的基本原理
The Laws of Reflection 反射定律:反射包的基本原理 6 September 2011 Introduction 介绍 Reflection in computing is th ...
- 4、Type fundamentals
1.All Types Are Derived from System.Object The CLR requires all objects to be created using the new ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-007UserTypes的用法(@org.hibernate.annotations.Type、@org.hibernate.annotations.TypeDefs、CompositeUserType、DynamicParameterizedType、、、)
一.结构 二.Hibernate支持的UserTypes接口 UserType —You can transform values by interacting with the plain JD ...
- Java里面instanceof怎么实现的
开始完全一头雾水呀,后面看了Java指令集的介绍,逐渐理解了. https://www.zhihu.com/question/21574535/answer/18998914 下面这个答案比较直白 你 ...
- 【转载】逃离adapter的地狱-针对多个View type的组合实现方案
英文原文:JOE'S GREAT ADAPTER HELL ESCAPE 转载地址:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015 ...
随机推荐
- Java代码里利用Fiddler抓包调试设置
Fiddler启动时已经将自己注册为系统的默认代理服务器,应用程序在访问网络时会去获取系统的默认代理,如果需要捕获java访问网络时的数据,只需要在启动java程序时设置代理服务器为Fiddler即可 ...
- struts2:使用JQuery、JSON和AJAX处理请求
目的 在struts2中使用JQuery.JSON.AJAX等技术处理用户请求,并返回结果.返回结果可以是以JSONObject的方式返回,也可以是以JSONArray方式返回结果. 实现 1. 创建 ...
- Pycharm中.py文件头信息配置
在社区版的Pycharm开发软件中设置每次新建.py文件都会自动生成如下信息 #! /usr/bin/env python # -*- coding:utf-8 -*- # Author: Tdcqm ...
- 【Tomcat】Tomcat 系统架构与设计模式,第 1 部分: 工作原理
这个分为两个部分的系列文章将研究 Apache Tomcat 的系统架构以及其运用的很多经典设计模式.本文是第 1 部分,将主要从 Tomcat 如何分发请求.如何处理多用户同时请求,还有它的多级容器 ...
- CINATRA发布第一个版本
cinatra是什么? cinatra是C++开源社区–purecpp发起的一个开源项目,现在正式发布第一个版本cinatra0.9.0,cinatra是一个现代C++写的web framework, ...
- [转]新人常识普及:我们为什么必须会git和maven
转自贴吧:http://tieba.baidu.com/p/3458400116 鉴于本吧多新人,新人又需要多交流才能进步,今天就给新人们讲讲git和maven的必要性,因为,他们的重要性,远远超过很 ...
- 使用python抓取58手机维修信息
之前在ququ的博客上看到说 python 中的BeautifulSoup 挺好玩的,今天下午果断下载下来,看了下api,挺好用的,完了2把,不错. 晚上写了一个使用python抓取58手机维修信息的 ...
- [NM]打开NetworkManager和wpa_supplicant的DEBUG接口
turn on the DEBUG log in /etc/NetworkManager/NetworkManager.conf and restart NetworkManager. [loggin ...
- 嵌入式开发之hi3519---GPIO 驱动
在一个嵌入式系统中使用最多的莫过于 通用输入输出 GPIO口.看到论坛中经常有朋友问海思为什么没有提供GPIO驱动.其实不然. 在海思SDK xxx/osdrv/tools/board_tools/ ...
- Kubernetes集群部署之一系统环境初始化
安装版本: centos version: 7.4 docker version: 18.03.1-ce kubectl version: v1.10.1 etcdctl version: 3.2.1 ...