Apparently this does not return true for callback arguments to many of the internal functions, such as array_map and array_walk.
(PHP 5 >= 5.4.0, PHP 7, PHP 8)
ReflectionParameter::isCallable — Verifica si el parámetro es de tipo callable
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.
Esta función está actualmente no documentada; solo la lista de sus argumentos está disponible.
Esta función no contiene ningún parámetro.
Retorna true
si el parámetro es de tipo callable, false
si no lo es, o null
si ocurre un error.
Versión | Descripción |
---|---|
8.0.0 | Esta función ahora está obsoleta, reemplazada por ReflectionParameter::getType(). |
Ejemplo #1 Equivalente PHP 8.0.0
A partir de PHP 8.0.0, el siguiente código indicará si un tipo soporta callables, incluyendo aquellos que forman parte de una unión.
<?php
function declaresCallable(ReflectionParameter $reflectionParameter): bool
{
$reflectionType = $reflectionParameter->getType();
if (!$reflectionType) return false;
$types = $reflectionType instanceof ReflectionUnionType
? $reflectionType->getTypes()
: [$reflectionType];
return in_array('callable', array_map(fn(ReflectionNamedType $t) => $t->getName(), $types));
}
?>
Apparently this does not return true for callback arguments to many of the internal functions, such as array_map and array_walk.