Note that the public member $class contains the name of the class in which the method has been defined:
<?php
class A {public function __construct() {}}
class B extends A {}
$method = new ReflectionMethod('B', '__construct');
echo $method->class; // prints 'A'
?>
The ReflectionMethod class
(PHP 5)
Introduction
The ReflectionMethod class reports information about a method.
Class synopsis
Properties
- name
-
Method name
- class
-
Class name
Predefined Constants
ReflectionMethod Modifiers
-
ReflectionMethod::IS_STATIC -
Indicates that the method is static.
-
ReflectionMethod::IS_PUBLIC -
Indicates that the method is public.
-
ReflectionMethod::IS_PROTECTED -
Indicates that the method is protected.
-
ReflectionMethod::IS_PRIVATE -
Indicates that the method is private.
-
ReflectionMethod::IS_ABSTRACT -
Indicates that the method is abstract.
-
ReflectionMethod::IS_FINAL -
Indicates that the method is final.
Table of Contents
- ReflectionMethod::__construct — Constructs a ReflectionMethod
- ReflectionMethod::export — Export a reflection method.
- ReflectionMethod::getClosure — Returns a dynamically created closure for the method
- ReflectionMethod::getDeclaringClass — Gets declaring class for the reflected method.
- ReflectionMethod::getModifiers — Gets the method modifiers
- ReflectionMethod::getPrototype — Gets the method prototype (if there is one).
- ReflectionMethod::invoke — Invoke
- ReflectionMethod::invokeArgs — Invoke args
- ReflectionMethod::isAbstract — Checks if method is abstract
- ReflectionMethod::isConstructor — Checks if method is a constructor
- ReflectionMethod::isDestructor — Checks if method is a destructor
- ReflectionMethod::isFinal — Checks if method is final
- ReflectionMethod::isPrivate — Checks if method is private
- ReflectionMethod::isProtected — Checks if method is protected
- ReflectionMethod::isPublic — Checks if method is public
- ReflectionMethod::isStatic — Checks if method is static
- ReflectionMethod::setAccessible — Set method accessibility
- ReflectionMethod::__toString — Returns the string representation of the Reflection method object.
webseiten dot designer at googlemail dot com ¶
2 years ago
no dot prob at gmx dot net ¶
7 years ago
I have written a function which returns the value of a given DocComment tag.
Full example:
<?php
header('Content-Type: text/plain');
class Example
{
/**
* This is my DocComment!
*
* @DocTag: prints Hello World!
*/
public function myMethod()
{
echo 'Hello World!';
}
}
function getDocComment($str, $tag = '')
{
if (empty($tag))
{
return $str;
}
$matches = array();
preg_match("/".$tag.":(.*)(\\r\\n|\\r|\\n)/U", $str, $matches);
if (isset($matches[1]))
{
return trim($matches[1]);
}
return '';
}
$method = new ReflectionMethod('Example', 'myMethod');
// will return Hello World!
echo getDocComment($method->getDocComment(), '@DocTag');
?>
Maybe you can add this functionality to the getDocComment methods of the reflection classes.
