Forum PHP 2025

ReflectionProperty::getHooks

(PHP 8 >= 8.4.0)

ReflectionProperty::getHooksこのプロパティに指定された全てのフックを配列で返す

説明

public ReflectionProperty::getHooks(): array

このプロパティに指定された全てのフックを配列で返します。

パラメータ

この関数にはパラメータはありません。

戻り値

対象となるフックをキーとする ReflectionMethod の配列を返します。 たとえば getset のフックを持つプロパティの場合、 getset のキーを持つ2要素を持つ配列を返します。 それらのそれぞれの要素は ReflectionMethod です。 返される要素の順番は定義されていません。 フックが定義されていない場合、空の配列が返されます。

例1 ReflectionProperty::getHooks() の例

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

public
int $count;
}

$rClass = new \ReflectionClass(Example::class);

$rProp = $rClass->getProperty('name');
var_dump($rProp->getHooks());

$rProp = $rClass->getProperty('count');
var_dump($rProp->getHooks());
?>

上の例の出力は以下となります。

array(1) {
  ["get"]=>
  object(ReflectionMethod)#3 (2) {
    ["name"]=>
    string(10) "$name::get"
    ["class"]=>
    string(7) "Example"
  }
}
array(0) {
}

参考

add a note

User Contributed Notes

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