As of 7.1, if a parameter type is found then this method returns an instance of ReflectionNamedType (https://www.php.net/manual/en/class.reflectionnamedtype.php), a subclass of ReflectionType.
(PHP 7)
ReflectionParameter::getType — Gets a parameter's type
Gets the associated type of a parameter.
В цієї функції немає параметрів.
Returns a ReflectionType object if a parameter type is
specified, NULL
otherwise.
Приклад #1 ReflectionParameter::getType() example
<?php
function someFunction(int $param, $param2) {}
$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();
$reflectionType1 = $reflectionParams[0]->getType();
$reflectionType2 = $reflectionParams[1]->getType();
echo $reflectionType1;
var_dump($reflectionType2);
Наведений вище приклад виведе щось подібне до:
int null
As of 7.1, if a parameter type is found then this method returns an instance of ReflectionNamedType (https://www.php.net/manual/en/class.reflectionnamedtype.php), a subclass of ReflectionType.