ReflectionProperty::getHook

(PHP 8 >= 8.4.0)

ReflectionProperty::getHookReturns a reflection object for a specified hook

说明

public ReflectionProperty::getHook(PropertyHookType $type): ?ReflectionMethod

Gets the reflection of the property's hook, if any.

参数

PropertyHookType
The type of hook to request.

返回值

If the requested hook is defined, a ReflectionMethod instance will be returned. If not, the method will return null

示例

示例 #1 ReflectionProperty::getHook() example

<?php
class Example
{
public
string $name { get => "Name here"; }
}

$rClass = new \ReflectionClass(Example::class);
$rProp = $rClass->getProperty('name');
var_dump($rProp->getHook(PropertyHookType::Get));
var_dump($rProp->getHook(PropertyHookType::Set));
?>

以上示例会输出:

object(ReflectionMethod)#4 (2) {
  ["name"]=>
  string(10) "$name::get"
  ["class"]=>
  string(7) "Example"
}
NULL

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top