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

ReflectionProperty::hasType

PHP function Edit on GitHub ✎

(PHP 7 >= 7.4.0, PHP 8)

Checks if property has a type

Description

ReflectionProperty::hasType(): bool

Checks if the property has a type associated with it.

Parameters Parameters

Return Values

true if a type is specified, false otherwise.

Examples

ReflectionProperty::hasType example

php
<?php
class User
{
    public string $name;
}

$rp = new ReflectionProperty('User', 'name');
var_dump($rp->hasType());
?>

The above example will output:

output
bool(true)

See Also

  • ReflectionProperty::getType
  • ReflectionProperty::isInitialized

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