ReflectionParameter
PHP Manual

ReflectionParameter::hasType

(PHP 7)

ReflectionParameter::hasType — Checks if parameter has a type

説明

public bool ReflectionParameter::hasType ( void )

Checks if the parameter has a type associated with it.

パラメータ

この関数にはパラメータはありません。

返り値

TRUE if a type is specified, FALSE otherwise.

例

例1 ReflectionParameter::hasType() example

<?php
function someFunction(string $param, $param2 = null) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();

var_dump($reflectionParams[0]->hasType());
var_dump($reflectionParams[1]->hasType());

上の例の出力は、 たとえば以下のようになります。

bool(true)
bool(false)

参考


ReflectionParameter
PHP Manual