ReflectionClass::hasProperty

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

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

说明

publicReflectionClass::hasProperty(string$name): bool

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

参数

name

待检查的属性的名称。

返回值

如果有这个属性返回 true,否则返回 false

示例

示例 #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)

参见

To Top