php8.5
Home/ Manual/ reflection / reflectiontype/ ReflectionType::__toString

ReflectionType::__toString

PHP function Edit on GitHub ✎

(PHP 7, PHP 8)

To string

Description

ReflectionType::__toString(): string

Gets the parameter type name.

Parameters Parameters

Return Values

Returns the type of the parameter.

Changelog

VersionDescription
8.0.0ReflectionType::__toString has been undeprecated.
7.1.0ReflectionType::__toString has been deprecated.

Examples

ReflectionType::__toString example

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

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

echo $reflectionParam->getType();

The above example will output something similar to:

output
string

See Also

  • ReflectionNamedType::getName
  • ReflectionNamedType::isBuiltin
  • ReflectionType::allowsNull
  • ReflectionUnionType::getTypes
  • ReflectionParameter::getType

Source: reference/reflection/reflectiontype/tostring.xml · from the official PHP manual (php/doc-en)