PhpRiot
Download Article
Download this article or the entire “Zend Framework 101” series with all listings and files.




More information
Related Books
Zend Framework, A Beginner's Guide

Zend Framework, A Beginner's Guide

Essential Skills--Made Easy! Leverage the power of the Zend Framework to supercharge...

Zend Framework 1.8 Web Application Development

Zend Framework 1.8 Web Application Development

Design, develop, and deploy feature-rich PHP web applications with this MVC framework...
PhpRiot Newsletter
Your Email Address:

More information

Zend Framework 101: Zend_Registry

Access the Registry Using Array Syntax

Because the Zend_Registry class extends the built-in ArrayObject class (see http://php.net/arrayobject for more details), it is possible to access the registry (read and write) using array notation.

This is extremely useful when you want to perform multiple registry operations in a single block of code, since it will clean up your code slightly from using the full static methods.

To access the registry using array notation, you must first retrieve the Zend_Registry instance using the Zend_Registry::getInstance() method.

Listing 4 shows an example of retrieving the Zend_Registry instance and reading and writing values.

Listing 4 Accessing the registry using array syntax (listing-4.php)
<?php
    require_once('Zend/Registry.php');
 
    $registry = Zend_Registry::getInstance();
 
    $registry['name'] = 'Quentin Zervaas';
 
    echo sprintf('My name is %s', $registry['name']);
?>
Tip: See the above link about ArrayObject if you want the ability to access objects using array notation. It can be extremely useful and provide some fairly powerful functionality.

In This Article