ReflectionProperty::getHooks
このプロパティに指定された全てのフックを配列で返す
説明
public array ReflectionProperty::getHooks()
このプロパティに指定された全てのフックを配列で返します。
戻り値
対象となるフックをキーとする ReflectionMethod
の配列を返します。
たとえば get と set のフックを持つプロパティの場合、
get と set のキーを持つ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