ReflectionParameter::hasType

(PHP 7, PHP 8)

ReflectionParameter::hasTypeVerifica si un parámetro tiene un tipo

Descripción

public ReflectionParameter::hasType(): bool

Verifica si el parámetro tiene un tipo asociado con este.

Parámetros

Esta función no tiene parámetros.

Valores devueltos

true si se especifica un tipo, false en caso contrario.

Ejemplos

Ejemplo #1 Ejemplo con ReflectionParameter::hasType()

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

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

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

El resultado del ejemplo sería algo similar a:

bool(true)
bool(false)

Ver también

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top