PHPTS:一键免费搭建 Nginx + PHP + MySQL 运行环境

ReflectionClass::hasProperty

(PHP 5 >= 5.1.2, PHP 7)

ReflectionClass::hasProperty检查属性是否已定义

说明

public ReflectionClass::hasProperty ( string $name ) : bool

检查指定的属性是否已定义。

参数

name

待检查的属性的名称。

返回值

如果有这个属性返回 TRUE,否则返回 FALSE

范例

Example #1 ReflectionClass::hasProperty() 例子

<?php
class Foo {
    public    
$p1;
    protected 
$p2;
    private   
$p3;

}

$obj = new ReflectionObject(new Foo());

var_dump($obj->hasProperty("p1"));
var_dump($obj->hasProperty("p2"));
var_dump($obj->hasProperty("p3"));
var_dump($obj->hasProperty("p4"));
?>

以上例程的输出类似于:

bool(true)
bool(true)
bool(true)
bool(false)

参见