class ReflectionMethod extends ReflectionFunctionAbstract (View source)

The ReflectionMethod class reports information about a method.

Constants

IS_STATIC

Indicates that the method is static.

IS_PUBLIC

Indicates that the method is public.

IS_PROTECTED

Indicates that the method is protected.

IS_PRIVATE

Indicates that the method is private.

IS_ABSTRACT

Indicates that the method is abstract.

IS_FINAL

Indicates that the method is final.

Properties

string $name
string $class

Methods

bool
inNamespace()

Checks if function in namespace

bool
isClosure()

Checks if closure

bool
isDeprecated()

Checks if deprecated

bool
isInternal()

Checks if is internal

bool
isUserDefined()

Checks if user defined

bool
isGenerator()

Returns whether this function is a generator

bool
isVariadic()

Returns whether this function is variadic

object|null
getClosureThis()

Returns this pointer bound to closure

getClosureScopeClass()

Returns the scope associated to the closure

string|false
getDocComment()

Gets doc comment

int|false
getEndLine()

Gets end line number

string|false
getExtensionName()

Gets extension name

string|false
getFileName()

Gets file name

string
getName()

Gets function name

string
getNamespaceName()

Gets namespace name

int
getNumberOfParameters()

Gets number of parameters

int
getNumberOfRequiredParameters()

Gets number of required parameters

array
getParameters()

Gets parameters

getReturnType()

Gets the specified return type of a function

string
getShortName()

Gets function short name

int|false
getStartLine()

Gets starting line number

array
getStaticVariables()

Gets static variables

bool
returnsReference()

Checks if returns reference

bool
hasReturnType()

Checks if the function has a specified return type

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

No description

bool
isStatic()

Checks if method is static

string
__toString()

Returns the string representation of the ReflectionMethod object.

__construct(string|object $objectOrMethod, string|null $method = null)

Constructs a ReflectionMethod

static string|null
export(string $class, string $name, bool $return = false)

Export a reflection method.

bool
isPublic()

Checks if method is public

bool
isPrivate()

Checks if method is private

bool
isProtected()

Checks if method is protected

bool
isAbstract()

Checks if method is abstract

bool
isFinal()

Checks if method is final

bool
isConstructor()

Checks if method is a constructor

bool
isDestructor()

Checks if method is a destructor

getClosure(object|null $object = null)

Returns a dynamically created closure for the method

int
getModifiers()

Gets the method modifiers

mixed
invoke(object|null $object, mixed ...$args)

Invokes a reflected method.

mixed
invokeArgs(object|null $object, array $args)

Invokes the reflected method and pass its arguments as array.

getDeclaringClass()

Gets declaring class for the reflected method.

getPrototype()

Gets the method prototype (if there is one).

void
setAccessible(bool $accessible)

Set method accessibility This method is no-op starting from PHP 8.1

bool
hasPrototype()

No description

createFromMethodName(string $method)

No description

Details

bool inNamespace()

Checks if function in namespace

Return Value

bool

{\true} if it's in a namespace, otherwise {\false}

bool isClosure()

Checks if closure

Return Value

bool

{\true} if it's a closure, otherwise {\false}

bool isDeprecated()

Checks if deprecated

Return Value

bool

{\true} if it's deprecated, otherwise {\false}

bool isInternal()

Checks if is internal

Return Value

bool

{\true} if it's internal, otherwise {\false}

bool isUserDefined()

Checks if user defined

Return Value

bool

{\true} if it's user-defined, otherwise {\false}

bool isGenerator()

Since: 5.5

Returns whether this function is a generator

Return Value

bool

{\true} if the function is generator, otherwise {\false}

bool isVariadic()

Since: 5.6

Returns whether this function is variadic

Return Value

bool

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

object|null getClosureThis()

Returns this pointer bound to closure

Return Value

object|null

Returns $this pointer or {\null} in case of an error.

ReflectionClass|null getClosureScopeClass()

Since: 5.4

Returns the scope associated to the closure

Return Value

ReflectionClass|null

Returns the class on success or {\null} on failure.

ReflectionClass|null getClosureCalledClass()

Since: 8.0

No description

Return Value

ReflectionClass|null

Returns the class on success or {\null} on failure.

string|false getDocComment()

Gets doc comment

Return Value

string|false

The doc comment if it exists, otherwise {\false}

int|false getEndLine()

Gets end line number

Return Value

int|false

The ending line number of the user defined function, or {\false} if unknown.

ReflectionExtension|null getExtension()

Gets extension info

Return Value

ReflectionExtension|null

The extension information, as a {\ReflectionExtension} object or {\null} instead.

string|false getExtensionName()

Gets extension name

Return Value

string|false

The extension's name or {\false} instead.

string|false getFileName()

Gets file name

Return Value

string|false

The file name or {\false} in case of error.

string getName()

Gets function name

Return Value

string

The name of the function.

string getNamespaceName()

Gets namespace name

Return Value

string

The namespace name.

int getNumberOfParameters()

Since: 5.0.3

Gets number of parameters

Return Value

int

The number of parameters.

int getNumberOfRequiredParameters()

Since: 5.0.3

Gets number of required parameters

Return Value

int

The number of required parameters.

array getParameters()

Gets parameters

Return Value

array

The parameters, as a ReflectionParameter objects.

ReflectionType|null getReturnType()

Since: 7.0

Gets the specified return type of a function

Return Value

ReflectionType|null

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

string getShortName()

Gets function short name

Return Value

string

The short name of the function.

int|false getStartLine()

Gets starting line number

Return Value

int|false

The starting line number or {\false} if unknown.

array getStaticVariables()

Gets static variables

Return Value

array

An array of static variables.

bool returnsReference()

Checks if returns reference

Return Value

bool

{\true} if it returns a reference, otherwise {\false}

bool hasReturnType()

Since: 7.0

Checks if the function has a specified return type

Return Value

bool

Returns {\true} if the function is a specified return type, otherwise {\false}.

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

array getClosureUsedVariables()

No description

Return Value

array

bool hasTentativeReturnType()

No description

Return Value

bool

ReflectionType|null getTentativeReturnType()

No description

Return Value

ReflectionType|null

bool isStatic()

Checks if method is static

Return Value

bool

string __toString()

Returns the string representation of the ReflectionMethod object.

Return Value

string

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

__construct(string|object $objectOrMethod, string|null $method = null)

Constructs a ReflectionMethod

$reflection = new ReflectionMethod(new Example(), 'method');
$reflection = new ReflectionMethod(Example::class, 'method');
$reflection = new ReflectionMethod('Example::method');

Parameters

string|object $objectOrMethod

Classname, object (instance of the class) that contains the method or class name and method name delimited by ::.

string|null $method

Name of the method if the first argument is a classname or an object.

Exceptions

ReflectionException

static string|null export(string $class, string $name, bool $return = false)

Export a reflection method.

Parameters

string $class

The class name.

string $name

The name of the method.

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

bool isPublic()

Checks if method is public

Return Value

bool

Returns {\true} if the method is public, otherwise {\false}

bool isPrivate()

Checks if method is private

Return Value

bool

Returns {\true} if the method is private, otherwise {\false}

bool isProtected()

Checks if method is protected

Return Value

bool

Returns {\true} if the method is protected, otherwise {\false}

bool isAbstract()

Checks if method is abstract

Return Value

bool

Returns {\true} if the method is abstract, otherwise {\false}

bool isFinal()

Checks if method is final

Return Value

bool

Returns {\true} if the method is final, otherwise {\false}

bool isConstructor()

Checks if method is a constructor

Return Value

bool

Returns {\true} if the method is a constructor, otherwise {\false}

bool isDestructor()

Checks if method is a destructor

Return Value

bool

Returns {\true} if the method is a destructor, otherwise {\false}

Closure getClosure(object|null $object = null)

Since: 5.4

Returns a dynamically created closure for the method

Parameters

object|null $object

Forbidden for static methods, required for other methods or nothing.

Return Value

Closure

Returns the newly created {\Closure}.

Exceptions

ValueError
ReflectionException

int getModifiers()

Gets the method modifiers

Return Value

int

A numeric representation of the modifiers. The modifiers are listed below. The actual meanings of these modifiers are described in the predefined constants.

ReflectionMethod modifiers:

mixed invoke(object|null $object, mixed ...$args)

Invokes a reflected method.

Parameters

object|null $object

The object to invoke the method on. For static methods, pass {\null} to this parameter.

mixed ...$args

Zero or more parameters to be passed to the method. It accepts a variable number of parameters which are passed to the method.

Return Value

mixed

Returns the method result.

Exceptions

ReflectionException

mixed invokeArgs(object|null $object, array $args)

Invokes the reflected method and pass its arguments as array.

Parameters

object|null $object

The object to invoke the method on. In case of static methods, you can pass {\null} to this parameter.

array $args

The parameters to be passed to the function, as an {\array}.

Return Value

mixed

the method result.

Exceptions

ReflectionException

ReflectionClass getDeclaringClass()

Gets declaring class for the reflected method.

Return Value

ReflectionClass

A {\ReflectionClass} object of the class that the reflected method is part of.

ReflectionMethod getPrototype()

Gets the method prototype (if there is one).

Return Value

ReflectionMethod

A {\ReflectionMethod} instance of the method prototype.

Exceptions

ReflectionException

void setAccessible(bool $accessible)

Set method accessibility This method is no-op starting from PHP 8.1

Parameters

bool $accessible

{\true} to allow accessibility, or {\false}

Return Value

void

No value is returned.

bool hasPrototype()

No description

Return Value

bool

static ReflectionMethod createFromMethodName(string $method)

Since: 8.3

No description

Parameters

string $method

Return Value

ReflectionMethod