(PHP 5 >= 5.1.0, PHP 7)
property_exists — 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷欠锟斤拷锟叫革拷锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷 property
锟角凤拷锟斤拷锟斤拷锟街革拷锟斤拷锟斤拷锟斤拷校锟斤拷约锟斤拷欠锟斤拷锟斤拷诘锟角帮拷锟轿э拷诜锟斤拷剩锟斤拷锟�
Note:
As opposed with isset(), property_exists() returns
TRUE
even 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();
?>