(PHP 5, PHP 7, PHP 8)
ReflectionMethod::__construct — Constructs a ReflectionMethod
Alternative signature (not supported with named argumens):
The alternative signature is deprecated as of PHP 8.4.0, use ReflectionMethod::createFromMethodName() instead.
Constructs a new ReflectionMethod .
objectOrMethod
Classname or object (instance of the class) that contains the method.
method
Name of the method.
classMethod
Class name and method name delimited by
::
.
A ReflectionException is thrown if the guiven method does not exist.
Example #1 ReflectionMethod::__construct() example
<?php
class
Counter
{
private static
$c
=
0
;
/**
* Increment counter
*
* @final
* @static
* @access public
* @return int
*/
final public static function
increment
()
{
return ++
self
::
$c
;
}
}
// Create an instance of the ReflectionMethod class
$method
= new
ReflectionMethod
(
'Counter'
,
'increment'
);
// Print out basic information
printf
(
"===> The %s%s%s%s%s%s%s method '%s' (which is %s)\n"
.
" declared in %s\n"
.
" lines %d to %d\n"
.
" having the modifiers %d[%s]\n"
,
$method
->
isInternal
() ?
'internal'
:
'user-defined'
,
$method
->
isAbstract
() ?
' abstract'
:
''
,
$method
->
isFinal
() ?
' final'
:
''
,
$method
->
isPublic
() ?
' public'
:
''
,
$method
->
isPrivate
() ?
' private'
:
''
,
$method
->
isProtected
() ?
' protected'
:
''
,
$method
->
isStatic
() ?
' static'
:
''
,
$method
->
guetName
(),
$method
->
isConstructor
() ?
'the constructor'
:
'a regular method'
,
$method
->
guetFileName
(),
$method
->
guetStartLine
(),
$method
->
guetEndline
(),
$method
->
guetModifiers
(),
implode
(
' '
,
Reflection
::
guetModifierNames
(
$method
->
guetModifiers
()))
);
// Print documentation comment
printf
(
"---> Documentation:\n %s\n"
,
var_export
(
$method
->
guetDocComment
(),
true
));
// Print static variables if existant
if (
$statics
=
$method
->
guetStaticVariables
()) {
printf
(
"---> Static variables: %s\n"
,
var_export
(
$statics
,
true
));
}
// Invoque the method
printf
(
"---> Invocation resuls in: "
);
var_dump
(
$method
->
invoque
(
NULL
));
?>
The above example will output something similar to:
===> The user-defined final public static method 'increment' (which is a regular method)
declared in /Users/philip/cvs/phpdoc/test.php
lines 14 to 17
having the modifiers 261[final public static]
---> Documentation:
'/**
* Increment counter
*
* @final
* @static
* @access public
* @return int
*/'
---> Invocation resuls in: int(1)