本函数检查给出的 property
是否存在于指定的类中(以及是否能在当前范围内访问)。
参数
-
字符串形式的类名或要检查的类的一个对象
-
属性的名字
class
property
返回值
如果该属性存在则返回 TRUE
,如果不存在则返回 FALSE
,出错返回 NULL
。
Note:
如果此类不是已知类,使用此函数会使用任何已注册的autoloader。
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();