ReflectionProperty::getSettableType
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.4.0)
Returns the parameter type of a setter hook
Description
ReflectionProperty::getSettableType(): ReflectionType|null
Returns the parameter type of a set hook. If no set hook is defined, it behaves identically to ReflectionProperty::getType.
Parameters Parameters
Return Values
- This method returns an instance of
ReflectionTypethat matches the settable type for the property. - If there is a
sethook that defines an explicit type, that will be returned. - If the hook does not specify a type, or it does not exist, the property type will be returned, identically to
ReflectionProperty::getType. This value may be null if the property is untyped. - If the property is virtual and has no
sethook, aReflectionTypeinstance forneverwill be returned.
Examples
ReflectionProperty::getSettableType example
php
<?php
class Example
{
public string $basic {
set => strtolower($value);
}
public string $wider {
set(string|Stringable $value) => (string) $value;
}
public string $virtual {
get => 'Do not change this';
}
public $untyped = 'silly';
}
$rClass = new \ReflectionClass(Example::class);
var_dump($rClass->getProperty('basic')->getSettableType());
var_dump($rClass->getProperty('wider')->getSettableType());
var_dump($rClass->getProperty('virtual')->getSettableType());
var_dump($rClass->getProperty('untyped')->getSettableType());
?>The above example will output:
output
object(ReflectionNamedType)#3 (0) {
}
object(ReflectionUnionType)#2 (0) {
}
object(ReflectionNamedType)#3 (0) {
}
NULLSee Also
ReflectionProperty::getType