23.2. Zend_Server_Reflection
上一页 | 第 23 章 Zend_Server | 下一页

## 23.2. Zend_Server_Reflection

### 23.2.1. Introduction

Zend_Server_Reflection provides a standard mechanism for performing function and class introspection for use with server classes. It is based on PHP 5's Reflection API, and extends it to provide methods for retrieving parameter and return value types and descriptions, a full list of function and method prototypes (i.e., all possible valid calling combinations), and function/method descriptions.

Typically, this functionality will only be used by developers of server classes for the framework.

### 23.2.2. Usage

Basic usage is simple:

    <?php
    require_once 'Zend/Server/Reflection.php';
    $class    = Zend_Server_Reflection::reflectClass('My_Class');
    $function = Zend_Server_Reflection::reflectFunction('my_function');

    // Get prototypes
    $prototypes = $reflection->getPrototypes();

    // Get prototype return type
    $prototype->getReturnType();

    // Get prototype parameters
    $prototype->getParameters();

    // Get parameter type
    $parameter->getType();

    // Get namespace for a class, function, or method.
    // Namespaces may be set at instantiation time (second argument), or using
    // setNamespace()
    $reflection->getNamespace();

`reflectFunction()` returns a `Zend_Server_Reflection_Function` object; `reflectClass` returns a `Zend_Server_Reflection_Class` object. Please refer to the API documentation to know what methods are available to each.

上一页 | 上一级 | 下一页
第 23 章 Zend_Server | 起始页 | 第 24 章 Zend_Service