PHP 8.5.0 Alpha 2 available for testing

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 contiene ningún parámetro.

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());

Resultado del ejemplo anterior es 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