La clase ReflectionFunction te permite funciones de ingeniería inversa.
Nota: invokeArgs() fue agregado en PHP 5.1.0.
Para entender directamente una función, primero tiene que crear una isntancia de la clase
ReflectionFunction. Hasta entonces puede llamar cualquier de los métodos anteriores en esta instancia.
Ejemplo 19-33. Usando la clase ReflectionFunction
<?php/** * A simple counter * * @return int */function counter() { static $c = 0; return $c++; } // Create an instance of the Reflection_Function class$func = new ReflectionFunction('counter'); // Print out basic informationprintf( "===> The %s function '%s'\n". " declared in %s\n". " lines %d to %d\n", $func->isInternal() ? 'internal' : 'user-defined', $func->getName(), $func->getFileName(), $func->getStartLine(), $func->getEndline() ); // Print documentation commentprintf("---> Documentation:\n %s\n", var_export($func->getDocComment(), 1)); // Print static variables if existantif ($statics = $func->getStaticVariables()) { printf("---> Static variables: %s\n", var_export($statics, 1)); } // Invoke the functionprintf("---> Invokation results in: ");var_dump($func->invoke());
// you may prefer to use the export() methodecho "\nReflectionFunction::export() results:\n"; echo ReflectionFunction::export('counter');?> |
|
Nota: El método invoke() acepta un número de variable de argumentos los cuales son pasados a la función tal y como se hace en call_user_func().
No response to “ReflectionFunction”
Publicar un comentario