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.

Приклади

Приклад #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
3 years 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