PHP 8.3.4 Released!

ReflectionParameter::hasType

(PHP 7, PHP 8)

ReflectionParameter::hasType引数が型を持つかを調べる

説明

public ReflectionParameter::hasType(): bool

引数が、関連する型を持つかを調べます。

パラメータ

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

戻り値

型が指定されていれば true を。そうでなければ false を返します。

例1 ReflectionParameter::hasType() の例

<?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)

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top