PHP 5.6.0 released

The ReflectionMethod class

Introduction

کلاس ReflectionMethod اطلاعاتی درباره متد ارائه می‌دهد.

Class synopsis

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

Properties

name

Prop description

class

Prop description

Predefined Constants

ReflectionMethod Node Types

ReflectionMethod::IS_STATIC

Description here...

ReflectionMethod::IS_PUBLIC

Description here...

ReflectionMethod::IS_PROTECTED

Description here...

ReflectionMethod::IS_PRIVATE

Description here...

ReflectionMethod::IS_ABSTRACT

Description here...

ReflectionMethod::IS_FINAL

Description here...

Table of Contents

add a note add a note

User Contributed Notes 2 notes

up
1
webseiten dot designer at googlemail dot com
3 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
-2
no dot prob at gmx dot net
8 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