首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ReflectionClass::hasProperty

(PHP 5 >= 5.1.0, PHP 7)

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

描述

代码语言:javascript
复制
public bool ReflectionClass::hasProperty ( string $name )

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

参数

name

正在检查的属性的名称。

返回值

TRUE 如果它有属性,否则 FALSE

例子

示例#1 ReflectionClass::hasProperty()示例

代码语言:javascript
复制
<?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"));
?>

上面的例子会输出类似于:

代码语言:javascript
复制
bool(true)
bool(true)
bool(true)
bool(false)

另请参阅

  • ReflectionClass::hasConstant() - 检查是否定义了常量
  • ReflectionClass::hasMethod() - 检查方法是否定义

← ReflectionClass::hasMethod

ReflectionClass::implementsInterface →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com