PHP Doku:: The ReflectionFunction class - class.reflectionfunction.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenReflectionThe ReflectionFunction class

Ein Service von Reinhard Neidl - Webprogrammierung.

Reflection

<<ReflectionExtension::__toString

ReflectionFunction::__construct>>


UnterSeiten:

The ReflectionFunction class

Einführung

The ReflectionFunction class reports information about a function.

Parent class ReflectionFunctionAbstract has the same methods except invoke(), invokeArgs(), export() and isDisabled().

Klassenbeschreibung

ReflectionFunction extends ReflectionFunctionAbstract implements Reflector {
/* Konstanten */
const integer ReflectionFunction::IS_DEPRECATED = 262144 ;
/* Eigenschaften */
public $name ;
/* Methoden */
__construct ( mixed $name )
public static string export ( string $name [, string $return ] )
public mixed invoke ([ mixed $parameter [, mixed $... ]] )
public mixed invokeArgs ( array $args )
public bool isDisabled ( void )
public string __toString ( void )
/* Geerbte Methoden */
final private void ReflectionFunctionAbstract::__clone ( void )
public ReflectionExtension ReflectionFunctionAbstract::getExtension ( void )
public string ReflectionFunctionAbstract::getName ( void )
abstract public void ReflectionFunctionAbstract::__toString ( void )
}

Eigenschaften

name

Prop description

Vordefinierte Konstanten

ReflectionFunction Node Types

ReflectionFunction::IS_DEPRECATED

Description here...

Inhaltsverzeichnis


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
uramihsayibok, gmail, com
24.10.2010 12:00
ReflectionFunction will not work on class methods - instance or static. That is,

<?php

class A {
    function
B() {}
    static function
C() {}
}

new
ReflectionFunction("A::B"); // throws "does not exist" ReflectionException
new ReflectionFunction("A::C"); // ditto

?>

The array syntax for method callbacks does not work either but throws a warning instead (__construct wants a string, not an array).
Since I don't know ahead of time whether something is a function or a class method, I have this:

<?php

function ReflectionFunctionFactory($callback) {
    if (
is_array($callback)) {
       
// must be a class method
       
list($class, $method) = $callback;
        return new
ReflectionMethod($class, $method);
    }

   
// class::method syntax
   
if (is_string($callback) && strpos($callback, "::") !== false) {
        list(
$class, $method) = explode("::", $callback);
        return new
ReflectionMethod($class, $method);
    }

   
// objects as functions (PHP 5.3+)
   
if (version_compare(PHP_VERSION, "5.3.0", ">=") && method_exists($callback, "__invoke")) {
        return new
ReflectionMethod($callback, "__invoke");
    }

   
// assume it's a function
   
return new ReflectionFunction($callback);
}

?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)