ReflectionParameter::hasType

(PHP 7, PHP 8)

ReflectionParameter::hasTypeChecks if parameter has a type

Descrição

publicReflectionParameter::hasType(): bool

Checks if the parameter has a type associated with it.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

true if a type is specified, false otherwise.

Exemplos

Exemplo #1 ReflectionParameter::hasType() example

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

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

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

O exemplo acima produzirá algo semelhante a:

bool(true) bool(false)

Veja Também

To Top