parent root
PHP: ReflectionMethod - Manual
PHP 7.2.23 Release Announcement

The ReflectionMethod class

(PHP 5, PHP 7)

Introduction

The ReflectionMethod class reports information about a method.

Class synopsis

ReflectionMethod extends ReflectionFunctionAbstract implements Reflector {
/* Constants */
const integer IS_STATIC = 1 ;
const integer IS_PUBLIC = 256 ;
const integer IS_PROTECTED = 512 ;
const integer IS_PRIVATE = 1024 ;
const integer IS_ABSTRACT = 2 ;
const integer IS_FINAL = 4 ;
/* Properties */
public $name ;
public $class ;
/* Methods */
public __construct ( mixed $class , string $name )
public static export ( string $class , string $name [, bool $return = FALSE ] ) : string
public getClosure ( object $object ) : Closure
public getModifiers ( void ) : int
public getPrototype ( void ) : ReflectionMethod
public invoke ( object $object [, mixed $... ] ) : mixed
public invokeArgs ( object $object , array $args ) : mixed
public isAbstract ( void ) : bool
public isConstructor ( void ) : bool
public isDestructor ( void ) : bool
public isFinal ( void ) : bool
public isPrivate ( void ) : bool
public isProtected ( void ) : bool
public isPublic ( void ) : bool
public isStatic ( void ) : bool
public setAccessible ( bool $accessible ) : void
public __toString ( void ) : string
/* Inherited methods */
final private ReflectionFunctionAbstract::__clone ( void ) : void
public ReflectionFunctionAbstract::getFileName ( void ) : string
public ReflectionFunctionAbstract::getName ( void ) : string
abstract public ReflectionFunctionAbstract::__toString ( void ) : void
}

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

add a noteadd a note

User Contributed Notes 2 notes

up
9
webseiten dot designer at googlemail dot com
8 years ago
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'
?>
up
-12
no dot prob at gmx dot net
13 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.
To Top
parent root