Introduction | Zend_Reflection Programmer's Reference Guide | Zend_Reflection Reference

# Zend_Reflection Examples

Example #1 Performing reflection on a file

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

Example #2 Performing reflection on a class

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

Example #3 Performing reflection on a method

1. $r = new Zend_Reflection_Method($class, $name);
3. printf(
4. "The method '%s' has a return type of %s",
5. $r->getName(),
6. $r->getReturn()
7. );
9. foreach ($r->getParameters() as $key => $param) {
10. printf(
11. "Param at position '%d' is of type '%s'\n",
12. $key,
13. $param->getType()
14. );
15. }

Example #4 Performing reflection on a docblock

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

Introduction | Zend_Reflection Programmer's Reference Guide | Zend_Reflection Reference