class ReflectionParameter implements Reflector (View source)

The ReflectionParameter class retrieves information about function's or method's parameters.

Properties

string $name

Methods

__construct(callable $function, string|int $param)

Construct

static string|null
export(string $function, string $parameter, bool $return = false)

Exports

string
__toString()

Returns the string representation of the ReflectionParameter object.

string
getName()

Gets parameter name

bool
isPassedByReference()

Checks if passed by reference

bool
canBePassedByValue()

Returns whether this parameter can be passed by value

getDeclaringClass()

Gets declaring class

getClass()

Gets the class type hinted for the parameter as a ReflectionClass object.

bool
hasType()

Checks if the parameter has a type associated with it.

getType()

Gets a parameter's type

bool
isArray()

Checks if parameter expects an array

bool
isCallable()

Returns whether parameter MUST be callable

bool
allowsNull()

Checks if null is allowed

int
getPosition()

Gets parameter position

bool
isOptional()

Checks if optional

bool
isDefaultValueAvailable()

Checks if a default value is available

mixed
getDefaultValue()

Gets default parameter value

bool
isDefaultValueConstant()

Returns whether the default value of this parameter is constant

string|null
getDefaultValueConstantName()

Returns the default value's constant name if default value is constant or null

bool
isVariadic()

Returns whether this function is variadic

bool
isPromoted()

Returns information about whether the parameter is a promoted.

array
getAttributes(string|null $name = null, int $flags = 0)

No description

Details

__construct(callable $function, string|int $param)

Construct

Parameters

callable $function

The function to reflect parameters from.

string|int $param

Either an integer specifying the position of the parameter (starting with zero), or a the parameter name as string.

Exceptions

ReflectionException

static string|null export(string $function, string $parameter, bool $return = false)

Exports

Parameters

string $function

The function name.

string $parameter

The parameter name.

bool $return

Setting to {\true} will return the export, as opposed to emitting it. Setting to {\false} (the default) will do the opposite.

Return Value

string|null

string __toString()

Returns the string representation of the ReflectionParameter object.

Return Value

string

Returns string representation of the object that implements this interface (and/or "__toString" magic method).

string getName()

Gets parameter name

Return Value

string

The name of the reflected parameter.

bool isPassedByReference()

Checks if passed by reference

Return Value

bool

{\true} if the parameter is passed in by reference, otherwise {\false}

bool canBePassedByValue()

Since: 5.4

Returns whether this parameter can be passed by value

Return Value

bool

{\true} if the parameter can be passed by value, {\false} otherwise. Returns {\null} in case of an error.

ReflectionFunctionAbstract getDeclaringFunction()

Since: 5.2.3

Gets declaring function

Return Value

ReflectionFunctionAbstract

A {\ReflectionFunctionAbstract} object.

ReflectionClass|null getDeclaringClass()

Gets declaring class

Return Value

ReflectionClass|null

A {\ReflectionClass} object or {\null} if called on function.

ReflectionClass|null getClass()

Gets the class type hinted for the parameter as a ReflectionClass object.

Return Value

ReflectionClass|null

A {\ReflectionClass} object.

See also

ReflectionParameter::getType

bool hasType()

Since: 7.0

Checks if the parameter has a type associated with it.

Return Value

bool

{\true} if a type is specified, {\false} otherwise.

ReflectionType|null getType()

Since: 7.0

Gets a parameter's type

Return Value

ReflectionType|null

Returns a {\ReflectionType} object if a parameter type is specified, {\null} otherwise.

bool isArray()

Checks if parameter expects an array

Return Value

bool

{\true} if an array is expected, {\false} otherwise.

See also

ReflectionParameter::getType

bool isCallable()

Since: 5.4

Returns whether parameter MUST be callable

Return Value

bool

Returns {\true} if the parameter is callable, {\false} if it is not or {\null} on failure.

See also

ReflectionParameter::getType

bool allowsNull()

Checks if null is allowed

Return Value

bool

Returns {\true} if {\null} is allowed, otherwise {\false}

int getPosition()

Since: 5.2.3

Gets parameter position

Return Value

int

The position of the parameter, left to right, starting at position #0.

bool isOptional()

Since: 5.0.3

Checks if optional

Return Value

bool

Returns {\true} if the parameter is optional, otherwise {\false}

bool isDefaultValueAvailable()

Since: 5.0.3

Checks if a default value is available

Return Value

bool

Returns {\true} if a default value is available, otherwise {\false}

mixed getDefaultValue()

Since: 5.0.3

Gets default parameter value

Return Value

mixed

The parameters default value.

Exceptions

ReflectionException

bool isDefaultValueConstant()

Since: 5.4.6

Returns whether the default value of this parameter is constant

Return Value

bool

Returns {\true} if the default value is constant, and {\false} otherwise.

string|null getDefaultValueConstantName()

Since: 5.4.6

Returns the default value's constant name if default value is constant or null

Return Value

string|null

Returns string on success or {\null} on failure.

Exceptions

ReflectionException

bool isVariadic()

Since: 5.6

Returns whether this function is variadic

Return Value

bool

Returns {\true} if the function is variadic, otherwise {\false}

bool isPromoted()

Since: 8.0

Returns information about whether the parameter is a promoted.

Return Value

bool

Returns {\true} if the parameter promoted or {\false} instead

array getAttributes(string|null $name = null, int $flags = 0)

Since: 8.0

No description

Parameters

string|null $name

Name of an attribute class

int $flags

Сriteria by which the attribute is searched.

Return Value

array