Home  >  Article  >  Backend Development  >  php中instanceof 与 is_a()区别分析_php技巧

php中instanceof 与 is_a()区别分析_php技巧

WBOY
WBOYOriginal
2016-05-16 20:22:16859browse

instanceof 运算符 和 is_a() 方法都是判断:某对象是否属于该类 或 该类是此对象的父类(用于确定一个 PHP 变量是否属于某一类 class 的实例)

是的话返回 TRUE,不是的话返回 FALSE

区别:

instanceof 运算符是 PHP 5 引进的。在此之前用 is_a(),但是后来 is_a() 被废弃而用 instanceof 替代了。

注意:

PHP 5.3.0 起,又恢复使用 is_a() 了。

总结:

现在PHP的服务环境普遍都使用PHP5.0+了,所以尽量使用 instanceof 来代替 is_a()

综上,如果你不知道你的服务器环境,那么建议你使用instanceof,以免造成不必要的麻烦

Statement:
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