您现在的位置是:首页 > 其他

李清波 2017-06-13 其他 1828 复制当前网址

property_exists


property_exists

(PHP 5 >= 5.1.0)

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


说明

bool property_exists ( mixed $class , string $property )

本函数检查给出的 property 是否存在于指定的类中(以及是否能在当前范围内访问)。 


Note: As opposed with isset(), property_exists() returns TRUE even if the property has the value NULL


参数

class

字符串形式的类名或要检查的类的一个对象 

property

属性的名字

返回值

如果该属性存在则返回 TRUE,如果不存在则返回 FALSE,出错返回 NULL


范例

<?php

class myClass {
    public $mine;
    private $xpto;

    static function test() {
        var_dump(property_exists('myClass', 'xpto')); // true, it can be accessed from here
    }
}

var_dump(property_exists('myClass', 'mine'));   //true
var_dump(property_exists(new myClass, 'mine')); //true
var_dump(property_exists('myClass', 'xpto'));   //false, isn't public
myClass::test();
?>

文章来源:http://liqingbo.com/blog-1387.html

评论