ReflectionProperty::getHooks

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

説明

public array ReflectionProperty::getHooks()

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

パラメータ

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

戻り値

対象となるフックをキーとする 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) {
}

参考

  • ReflectionMethod
  • ReflectionProperty::hasHooks