Difference between Zend_Registry and Zend_Session

The use of these objects was confusing to me at first.. The basic difference between these objects is the ‘scope’ in which they are valid:

a) Zend_Registry : request scope
b) Zend_Session : session scope

Zend_Registry is used to store objects/values for the current request. In short, anything that you commit to Registry in index.php can be accessed from other controllers/actions (because EVERY request is first routed to the index.php bootstrapper via the .htaccess file). Config parameters and db parameters are generally prepped for global use using the Zend_Registry object.

Zend_Session actually uses PHP sessions. Data stored using Zend_Session can be accessed in different/all pages. So, if you want to create a variable named ‘UserRole’ in the /auth/login script and want it to be accessible in /auth/redirect, you would use Zend_Session.


2 thoughts on “Difference between Zend_Registry and Zend_Session

  1. Well said Shankar.

    @Bajarang: Request Scope means, in a simple word,
    let’s say you have a DB object stored in the registry, and when you are access a page say login page, this particular DB object will be accessible to any of the files used in that page (to construct), meaning global access (same keyword in PHP http://in2.php.net/manual/en/language.variables.scope.php#language.variables.scope.global).

    Whereas, Session scope means you can access anywhere on any page until you close your browser (until your session get’s destroyed).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s