PHP中的property_exists()函数
property_exists()方法检查对象或类是否具有属性。
语法
property_exists(object, property)
参数
object/class-对象或类名
property-属性的名称
返回
如果属性存在,property_exists()函数将返回TRUE,如果属性不存在,则返回FALSE,如果发生错误,则返回NULL。
示例
以下是一个例子-
<?php
class Demo {
public $one;
private $two;
static protected $VAL;
static function VAL() {
var_dump(property_exists('myClass', 'two'));
}
}
var_dump(property_exists('Demo', 'one'));
var_dump(property_exists(new Demo, 'one'));
?>输出结果
以下是输出-
bool(true) bool(true)