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 ...
随机推荐
- [svc]arp协议的细枝末节
tcpdump抓取arp包 tcpdump -nn -i calif24874aae57 -e arp数据包格式 操作字段指出四种操作类型: arp请求 1 arp应答 2 rarp请求 3 rarp ...
- KVM上如何让虚拟机支持虚拟化(kvm虚拟化的嵌套)
http://blog.csdn.net/swimming_in_it_/article/details/53320141http://blog.csdn.net/wickedglory/articl ...
- post请求数据量过大,提交失败
HttpRuntimeSection.MaxRequestLength 属性,请求的最大大小(以千字节为单位). 默认大小为 4096 KB (4 MB) <system.web> < ...
- 【iCore1S 双核心板_FPGA】例程二:GPIO输入实验——识别按键输入
实验现象: iCore1s 双核心板上与FPGA相连的三色LED(PCB上标示为FPGA·LED),按键按下红灯点亮,松开按键红灯熄灭. 核心源代码: module KEY( input CLK_12 ...
- 【6集iCore3_ADP触摸屏驱动讲解视频】6-3 底层驱动之液晶显示
源视频包下载地址: 链接:http://pan.baidu.com/s/1pKSUU2v 密码:4zme 银杏科技优酷视频发布区: http://i.youku.com/gingko8
- EventBus vs Otto vs Guava--自定义消息总线
同步发表于http://avenwu.net/ioc/2015/01/29/custom_eventbus Fork on github https://github.com/avenwu/suppo ...
- Cocos2dx网络读取图片
// // Connection.h // XXDemo // // Created by LeeHonGee on 14-9-4. // // #ifndef __XXDemo__Connectio ...
- Redis介绍以及安装(Linux)
Redis介绍以及安装(Linux) redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的 ...
- Intellij IDEA 2015 导入MyEClipse工程
一.步骤说明 File->New->Projet from existing sources,选择要导入的项目,并且导入项目; 打开 “open module settings”进行设置: ...
- [PGM] Variable elimination and Belief propagation
内容范围如题.Lec 08-11的内容:https://www.youtube.com/watch?v=Qa04kw1gKHk&index=36&list=PLQiVpyxVlLkbp ...