You could always use the singleton pattern and create a registry like object, for example:
CODE
<?php
class registry
{
const ERR_PROPERTY_NON_EXISTANT = 1;
public static $instance;
private $registry;
public function __construct($registry)
{
if(!is_array($registry))
{
$this->registry = array();
}
else
{
$this->registry = $registry;
}
}
public static function getRegistry($registry = false)
{
if(!isset(self::$instance))
{
self::$instance = new self($registry);
}
return self::$instance;
}
public function __get($property)
{
if(isset($this->registry[$property]))
{
return $this->registry[$property];
}
else
{
throw new Exception('Registry property does not exist.', self::ERR_PROPERTY_NON_EXISTANT);
}
}
public function __set($property, $value)
{
$this->registry[$property] = $value;
}
}
/*
* Example usage
*/
$set = array(
'foo' => 'I am foo.',
'bar' => 'I am bar.'
);
// Notice no 'new' keyword for instantiation
$registry = registry::getRegistry($set);
// Use object's getter to retrieve value
echo $registry->foo, "\n", $registry->bar, "\n";
// set a new registered item (or change an existing) with object's setter
$registry->bork = 'I am bork.';
echo $registry->bork, "\n";
?>