Forum PHP 2025

ReflectionProperty::getHook

(PHP 8 >= 8.4.0)

ReflectionProperty::getHook指定したフックに対応するリフレクションオブジェクトを返す

説明

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

プロパティフックが存在した場合、対応するリフレクションオブジェクトを返します。

パラメータ

PropertyHookType
プロパティフックのタイプ

戻り値

指定されたフックが定義されている場合、 ReflectionMethod のインスタンスを返します。 定義されていない場合、null を返します。

例1 ReflectionProperty::getHook() の例

<?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
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top