php8.5
Home/ Manual/ reflection / reflectionparameter/ ReflectionParameter::getClass

ReflectionParameter::getClass

PHP function Deprecated as of PHP 8.0.0 Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Get a ReflectionClass object for the parameter being reflected or null

Function-8-0-0

Description

ReflectionParameter::getClass(): ReflectionClass|null

Gets a ReflectionClass object for the parameter being reflected or null.

As of PHP 8.0.0 this function is deprecated and not recommended. Instead, use ReflectionParameter::getType to get the ReflectionType of the parameter, then interrogate that object to determine the parameter type.

Func

Parameters Parameters

Return Values

A ReflectionClass object, or null if no type is declared, or the declared type is not a class or interface.

Examples

Using the ReflectionParameter class

php
<?php
function foo(Exception $a) { }

$functionReflection = new ReflectionFunction('foo');
$parameters = $functionReflection->getParameters();
$aParameter = $parameters[0];

echo $aParameter->getClass()->name;
?>

Changelog

VersionDescription
8.0.0This function has been deprecated in favor of ReflectionParameter::getType instead.

See Also

  • ReflectionParameter::getDeclaringClass

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