In php programming we always used global or $_GLOBALS to refer to the global variable.

For example consider below -

Db.php

<?php

// connect to mysql server
$mysqlLink = mysql_connect("mysql_server", "mysql_user", "mysql_password");
?>

index.php

<?php
require_once "Db.php";
function displayTables()
{
global $mysqlLink;

$sql = "SHOW TABLES";

//use global variable mysqlLink, and perform query execution

mysql_query($sql, $mysqlLink);

?>

In zend framework, zend registry is an mechanism to using global storage. The registry is used as container for storing reusable objects and values, which will be available throughout our application.Zend framework examples | Zend registry -Example 1: In this example we will store the consumer name, in the consumer session name space. And register the consumer session namespace in the zend registry.

<?php
require_once "Zend/Session.php";
require_once "Zend/Session/Namespace.php";

Zend_Session::start();
$consumer = new Zend_Session_Namespace("consumer");
Zend_Registry::set(’consumer’, $consumer);
$consumer->name = "Ganesh";
?>

In this example, we will retrieve the session value, using zend registry.

<?php
echo "Consumer name:" . Zend_Registry::get('consumer')->name;
?>
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Simpy
  • StumbleUpon
  • Technorati
  • YahooMyWeb