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)
热门推荐
10 病人祝福语老师寄语简短
11 新娘生孩子祝福语简短
12 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短