property_exists
(PHP 5 >= 5.1.0, PHP 7)
property_exists — 检查对象或类是否具有该属性
说明
   本函数检查给出的 property 是否存在于指定的类中(以及是否能在当前范围内访问)。
  
Note:
As opposed with isset(), property_exists() returns
TRUEeven if the property has the valueNULL.
参数
- 
class
- 
       字符串形式的类名或要检查的类的一个对象 
- 
property
- 
       属性的名字 
返回值
   如果该属性存在则返回 TRUE,如果不存在则返回 FALSE,出错返回 NULL。
  
注释
Note:
如果此类不是已知类,使用此函数会使用任何已注册的 autoloader。
Note:
The property_exists() function cannot detect properties that are magically accessible using the __get magic method.
更新日志
| 版本 | 说明 | 
|---|---|
| 5.3.0 | This function checks the existence of a property independent of accessibility. | 
范例
Example #1 A property_exists() example
<?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, as of PHP 5.3.0
var_dump(property_exists('myClass', 'bar'));    //false
var_dump(property_exists('myClass', 'test'));   //true, as of PHP 5.3.0
myClass::test();
?>