ReflectionType::__toString

(PHP 7, PHP 8)

ReflectionType::__toString文字列に変換する

説明

public ReflectionType::__toString(): string

引数の型の名前を取得します。

パラメータ

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

戻り値

引数の型を返します。

変更履歴

バージョン 説明
8.0.0 ReflectionType::__toString() は非推奨ではなくなりました。
7.1.0 ReflectionType::__toString() は非推奨になりました。

例1 ReflectionType::__toString() の例

<?php
function someFunction(string $param) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParam = $reflectionFunc->getParameters()[0];

echo $reflectionParam->getType();

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

string

参考