PHP 8.5.0 Alpha 1 available for testing

ReflectionParameter::isArray

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

ReflectionParameter::isArrayVerifica si el parámetro espera un array

Advertencia

Esta función está OBSOLETA a partir de PHP 8.0.0. Depender de esta función está fuertemente desaconsejado.

Ver el ejemplo a continuación para un método alternativo para obtener esta información.

Descripción

#[\Deprecated]
public ReflectionParameter::isArray(): bool

Verifica si el parámetro espera un array.

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

true si el parámetro espera un array, false en caso contrario.

Historial de cambios

Versión Descripción
8.0.0 Esta función ha sido deprecada en favor del método ReflectionParameter::getType().

Ejemplos

Ejemplo #1 Equivalente en PHP 8.0.0

A partir de PHP 8.0.0, el siguiente código indica si un tipo soporta arrays, incluyendo aquellos que forman parte de una unión.

<?php
function declaresArray(ReflectionParameter $reflectionParameter): bool
{
$reflectionType = $reflectionParameter->getType();

if (!
$reflectionType) return false;

$types = $reflectionType instanceof ReflectionUnionType
? $reflectionType->getTypes()
: [
$reflectionType];

return
in_array('array', array_map(fn(ReflectionNamedType $t) => $t->getName(), $types));
}
?>

Ver también

add a note

User Contributed Notes

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