
property_exists() 函数检查对象或类是否具有该属性
语法
property_exists ( $object, $property );
定义和用法
此函数检查给定的属性是否存在于指定的类中(以及是否可以从当前作用域访问)。
参数
| 序号 | 参数及说明 | 
|---|---|
| 1 | object(必需) 字符串形式的类名或要检查的类的一个对象 | 
| 2 | property(必需) 属性的名称。 | 
返回值
如果该属性存在,则返回TRUE;如果该属性不存在,则返回FALSE;如果发生错误,则返回NULL。
在线示例
以下是此函数的用法-
<?php
class myClass {
    public $mine;
    private $xpto;
    static protected $test;
    static function test() {
        var_dump(property_exists('myClass', 'xpto')); //true
    }
}
var_dump(property_exists('myClass', 'mine'));   //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto'));   //true, 从PHP 5.3.0开始
var_dump(property_exists('myClass', 'bar'));    //false
var_dump(property_exists('myClass', 'test'));   //true, 从PHP 5.3.0开始
myClass::test();
?>
                    
                