Zend\Server\Reflection

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, augmenting it with 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 or method descriptions.

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

Usage

Basic usage is simple:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$class    = Zend\Server\Reflection::reflectClass('My\Class');
$function = Zend\Server\Reflection::reflectFunction('my_function');

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

// Loop through each prototype for the function
foreach ($prototypes as $prototype) {

    // Get prototype return type
    echo "Return type: ", $prototype->getReturnType(), "\n";

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

    echo "Parameters: \n";
    foreach ($parameters as $parameter) {
        // Get parameter type
        echo "    ", $parameter->getType(), "\n";
    }
}

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

reflectFunction() returns a Zend\Server\Reflection\Function object; reflectClass() returns a Zend\Server\Reflection\Class object. Please refer to the API documentation to see what methods are available to each.

Project Versions

Table Of Contents

Previous topic

Introduction

Next topic

Zend\ServiceManager

This Page

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Server\Reflection on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.