您的位置:首页 > 运维架构

property_exists — 检查对象或类是否具有该属性

2017-01-06 10:10 363 查看
bool
property_exists ( mixed
$class
, string
$property
)
本函数检查给出的
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();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: