PHP is_object() 函数

PHP 教程 · 2019-01-31 19:29:47

is_object() 函数用于检测变量是否是一个对象。

PHP 版本要求: PHP 4, PHP 5, PHP 7

语法

bool is_object ( mixed $var )

参数说明:

  • $var:要检测的变量。

返回值

如果指定变量为对象,则返回 TRUE,否则返回 FALSE。

实例

实例

<?php function get_subjects($obj_name) { if(!is_object($obj_name)) { return(false); } return($obj_name->subjects); } $obj_name = new stdClass; $obj_name->subjects = Array('Google', 'Codercto', 'Facebook'); var_dump(get_subjects(NULL)); var_dump(get_subjects($obj_name)); ?>

输出结果为:

bool(false)
array(3) {
  [0]=>
  string(6) "Google"
  [1]=>
  string(6) "Codercto"
  [2]=>
  string(8) "Facebook"
}

点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html

查看所有标签

CSS

CSS

David Sawyer McFarland / O'Reilly / 2006-08-24 / USD 34.99

Book Description Web site design has grown up. Unlike the old days, when designers cobbled together chunky HTML, bandwidth-hogging graphics, and a prayer to make their sites look good, Cascading St......一起来看看 《CSS》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试