ReflectionProperty::getType
PHP function
Edit on GitHub ✎
(PHP 7 >= 7.4.0, PHP 8)
Gets a property's type
Description
ReflectionProperty::getType(): ReflectionType|null
Gets the associated type of a property.
Parameters Parameters
Return Values
Returns a ReflectionType if the property has a type, and null otherwise.
Examples
ReflectionProperty::getType example
php
<?php
class User
{
public string $name;
}
$rp = new ReflectionProperty('User', 'name');
echo $rp->getType()->getName();
?>The above example will output:
output
stringSee Also
ReflectionProperty::hasTypeReflectionProperty::isInitialized