1.8. Zend::registry($index = null)
Prev | Chapter 1. Zend | Next

## 1.8. Zend::registry($index = null)

Returns a value stored at offset $index in the registry, or the registry itself.

Example 1.2. registry() / offsetGet() Example

    <?php
    Zend::registry($index=null)

    // or

    $registry = Zend::registry();
    $value = $registry->offsetGet($index);
    ?>

If a value has been stored at the `$index` offset, that value will be returned. If the `$index` argument is `NULL`, the registry itself will be returned (a subclass of ArrayObject ). This method simply wraps the offsetGet() method , with the additional behavior of returned the registry if $index is not given.

To quickly determine if an index is present in the registry, use Zend::isRegistered():

Example 1.3. isRegistered() / offsetExists() Example

    <?php
    Zend::isRegistered($index=null)

    // or

    $registry = Zend::registry();
    echo $registry->offsetExists($index) ? 'exists' : 'does not exist';
    ?>

Iteration requires little effort:

Example 1.4. Iterating Over the Registry

    <?php
    foreach (Zend::registry() as $index => $value) {
        echo "$index => $value<br />\n";
    }
    ?>

Prev | Up | Next
1.7. Zend::register($index, $newval) | Home | 1.9. Zend::initRegistry($registry = 'Zend_Registry')