php8.5
Home/ Manual/ reflection / reflectionproperty/ ReflectionProperty::hasHook

ReflectionProperty::hasHook

PHP function Edit on GitHub ✎

(PHP 8 >= 8.4.0)

Returns whether the property has a given hook defined

Description

ReflectionProperty::hasHook(PropertyHookType $type): bool

Returns whether the property has a given hook defined.

Parameters

PropertyHookType

The type of hook to check for.

Return Values

Returns true if the hook is defined on this property, false if not.

Examples

ReflectionProperty::hasHook example

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

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

The above example will output:

output
bool(true)
bool(false)

See Also

  • ReflectionMethod
  • PropertyHookType

Source: reference/reflection/reflectionproperty/hashook.xml · from the official PHP manual (php/doc-en)