class Reflection

PHP reflection helpers.

Constants

BUILTIN_TYPES

Methods

static bool
isBuiltinType(string $type)

Determines if type is PHP built-in type. Otherwise, it is the class name.

static string|null
getReturnType(ReflectionFunctionAbstract $func)

Returns the type of return value of given function or method and normalizes self, static, and parent to actual class names.

static array
getReturnTypes(ReflectionFunctionAbstract $func)

Returns the types of return value of given function or method and normalizes self, static, and parent to actual class names.

static string|null
getParameterType(ReflectionParameter $param)

Returns the type of given parameter and normalizes self and parent to the actual class names.

static array
getParameterTypes(ReflectionParameter $param)

Returns the types of given parameter and normalizes self and parent to the actual class names.

static string|null
getPropertyType(ReflectionProperty $prop)

Returns the type of given property and normalizes self and parent to the actual class names.

static array
getPropertyTypes(ReflectionProperty $prop)

Returns the types of given property and normalizes self and parent to the actual class names.

static mixed
getParameterDefaultValue(ReflectionParameter $param)

Returns the default value of parameter. If it is a constant, it returns its value.

static ReflectionClass
getPropertyDeclaringClass(ReflectionProperty $prop)

Returns a reflection of a class or trait that contains a declaration of given property. Property can also be declared in the trait.

getMethodDeclaringMethod(ReflectionMethod $method)

Returns a reflection of a method that contains a declaration of $method.

static bool
areCommentsAvailable()

Finds out if reflection has access to PHPdoc comments. Comments may not be available due to the opcode cache.

static string
toString(Reflector $ref)

No description

static string
expandClassName(string $name, ReflectionClass $context)

Expands the name of the class to full name in the given context of given class.

static array
getUseStatements(ReflectionClass $class)

No description

Details

at line 31
static bool isBuiltinType(string $type)

Determines if type is PHP built-in type. Otherwise, it is the class name.

Parameters

string $type

Return Value

bool

at line 42
static string|null getReturnType(ReflectionFunctionAbstract $func)

Returns the type of return value of given function or method and normalizes self, static, and parent to actual class names.

If the function does not have a return type, it returns null. If the function has union type, it throws Nette\InvalidStateException.

Parameters

ReflectionFunctionAbstract $func

Return Value

string|null

at line 51
static array getReturnTypes(ReflectionFunctionAbstract $func)

Returns the types of return value of given function or method and normalizes self, static, and parent to actual class names.

Parameters

ReflectionFunctionAbstract $func

Return Value

array

at line 62
static string|null getParameterType(ReflectionParameter $param)

Returns the type of given parameter and normalizes self and parent to the actual class names.

If the parameter does not have a type, it returns null. If the parameter has union type, it throws Nette\InvalidStateException.

Parameters

ReflectionParameter $param

Return Value

string|null

at line 71
static array getParameterTypes(ReflectionParameter $param)

Returns the types of given parameter and normalizes self and parent to the actual class names.

Parameters

ReflectionParameter $param

Return Value

array

at line 82
static string|null getPropertyType(ReflectionProperty $prop)

Returns the type of given property and normalizes self and parent to the actual class names.

If the property does not have a type, it returns null. If the property has union type, it throws Nette\InvalidStateException.

Parameters

ReflectionProperty $prop

Return Value

string|null

at line 91
static array getPropertyTypes(ReflectionProperty $prop)

Returns the types of given property and normalizes self and parent to the actual class names.

Parameters

ReflectionProperty $prop

Return Value

array

at line 154
static mixed getParameterDefaultValue(ReflectionParameter $param)

Returns the default value of parameter. If it is a constant, it returns its value.

Parameters

ReflectionParameter $param

Return Value

mixed

Exceptions

ReflectionException If the parameter does not have a default value or the constant cannot be resolved

at line 185
static ReflectionClass getPropertyDeclaringClass(ReflectionProperty $prop)

Returns a reflection of a class or trait that contains a declaration of given property. Property can also be declared in the trait.

Parameters

ReflectionProperty $prop

Return Value

ReflectionClass

at line 203
static ReflectionMethod getMethodDeclaringMethod(ReflectionMethod $method)

Returns a reflection of a method that contains a declaration of $method.

Usually, each method is its own declaration, but the body of the method can also be in the trait and under a different name.

Parameters

ReflectionMethod $method

Return Value

ReflectionMethod

at line 237
static bool areCommentsAvailable()

Finds out if reflection has access to PHPdoc comments. Comments may not be available due to the opcode cache.

Return Value

bool

at line 244
static string toString(Reflector $ref)

Parameters

Reflector $ref

Return Value

string

at line 267
static string expandClassName(string $name, ReflectionClass $context)

Expands the name of the class to full name in the given context of given class.

Thus, it returns how the PHP parser would understand $name if it were written in the body of the class $context.

Parameters

string $name
ReflectionClass $context

Return Value

string

Exceptions

InvalidArgumentException

at line 299
static array getUseStatements(ReflectionClass $class)

Parameters

ReflectionClass $class

Return Value

array of [alias => class]

Traits

Static class.