Documentation

Zend_Reflection Examples - Zend_Reflection

Zend_Reflection Examples

Example #1 Performing reflection on a file

  1. $r = new Zend_Reflection_File($filename);
  2.     "===> The %s file\n".
  3.     "     has %d lines\n",
  4.     $r->getFileName(),
  5.     $r->getEndLine()
  6. );
  7.  
  8. $classes = $r->getClasses();
  9. echo "     It has " . count($classes) . ":\n";
  10. foreach ($classes as $class) {
  11.     echo "         " . $class->getName() . "\n";
  12. }
  13.  
  14. $functions = $r->getFunctions();
  15. echo "     It has " . count($functions) . ":\n";
  16. foreach ($functions as $function) {
  17.     echo "         " . $function->getName() . "\n";
  18. }

Example #2 Performing reflection on a class

  1. $r = new Zend_Reflection_Class($class);
  2.  
  3.     "The class level docblock has the short description: %s\n".
  4.     "The class level docblock has the long description:\n%s\n",
  5.     $r->getDocblock()->getShortDescription(),
  6.     $r->getDocblock()->getLongDescription(),
  7. );
  8.  
  9. // Get the declaring file reflection
  10. $file = $r->getDeclaringFile();

Example #3 Performing reflection on a method

  1. $r = new Zend_Reflection_Method($class, $name);
  2.  
  3. printf( "Method '%s':\n", $r->getName());
  4.  
  5. foreach ($r->getParameters() as $key => $param) {
  6.     printf(
  7.         "Param at position '%d' is of type '%s'\n",
  8.         $key,
  9.         $param->getType()
  10.     );
  11. }

Example #4 Performing reflection on a docblock

  1. $r = new Zend_Reflection_Method($class, $name);
  2. $docblock = $r->getDocblock();
  3.  
  4.     "The short description: %s\n".
  5.     "The long description:\n%s\n",
  6.     $r->getDocblock()->getShortDescription(),
  7.     $r->getDocblock()->getLongDescription(),
  8. );
  9.  
  10. foreach ($docblock->getTags() as $tag) {
  11.     printf(
  12.         "Annotation tag '%s' has the description '%s'\n",
  13.         $tag->getName(),
  14.         $tag->getDescription()
  15.     );
  16. }

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts