php8.5
Home/ Manual/ reflection / reflectionparameter/ ReflectionParameter::hasType

ReflectionParameter::hasType

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

Checks if parameter has a type

Description

ReflectionParameter::hasType(): bool

Checks if the parameter has a type associated with it.

Parameters Parameters

Return Values

true if a type is specified, false otherwise.

Examples

ReflectionParameter::hasType example

php
<?php
function someFunction(string $param, $param2 = null) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();

var_dump($reflectionParams[0]->hasType());
var_dump($reflectionParams[1]->hasType());

The above example will output something similar to:

output
bool(true)
bool(false)

See Also

  • ReflectionParameter::getType

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