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.
Example #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.