ReflectionParameter::getType

(PHP 7)

ReflectionParameter::getTypeGets a parameter's type

설명

public ReflectionType ReflectionParameter::getType ( void )

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

참고

add a note add a note

User Contributed Notes 1 note

up
1
Will Beaumont
1 year ago
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.
To Top