PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Zend_Reflection Examples

Example 680. Performing reflection on a file

<?php
$r 
= new Zend_Reflection_File($filename);
printf(
    
"===> The %s file\n".
    
"     has %d lines\n",
    
$r->getFileName(),
    
$r->getEndLine()
);

$classes $r->getClasses();
echo 
"     It has " count($classes) . ":\n";
foreach (
$classes as $class) {
    echo 
"         " $class->getName() . "\n";
}

$functions $r->getFunctions();
echo 
"     It has " count($functions) . ":\n";
foreach (
$functions as $function) {
    echo 
"         " $function->getName() . "\n";
}

Example 681. Performing reflection on a class

<?php
$r 
= new Zend_Reflection_Class($class);

printf(
    
"The class level docblock has the short description: %s\n".
    
"The class level docblock has the long description:\n%s\n",
    
$r->getDocblock()->getShortDescription(),
    
$r->getDocblock()->getLongDescription(),
);

// Get the declaring file reflection
$file $r->getDeclaringFile();

Example 682. Performing reflection on a method

<?php
$r 
= new Zend_Reflection_Method($class$name);

printf"Method '%s':\n"$r->getName());

foreach (
$r->getParameters() as $key => $param) {
    
printf(
        
"Param at position '%d' is of type '%s'\n",
        
$key,
        
$param->getType()
    );
}

Example 683. Performing reflection on a docblock

<?php
$r 
= new Zend_Reflection_Method($class$name);
$docblock $r->getDocblock();

printf(
    
"The short description: %s\n".
    
"The long description:\n%s\n",
    
$r->getDocblock()->getShortDescription(),
    
$r->getDocblock()->getLongDescription(),
);

foreach (
$docblock->getTags() as $tag) {
    
printf(
        
"Annotation tag '%s' has the description '%s'\n",
        
$tag->getName(),
        
$tag->getDescription()
    );
}

Zend Framework