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 Framework 101: Zend_Registry

Access the Registry Using Array Syntax

Because the Zend_Registry class extends the built-in ArrayObject class (see 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)
    $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