registry[$key] = $val; } public function get(string $key, $default = false) { if (isset($this->registry[$key])) return $this->registry[$key]; else return $default; } public function getAll() { return $this->registry; } public function unset(string $key) { if (isset($this->registry[$key])) unset($this->registry[$key]); } } /** * demo */ echo '
'; // for print in browser

# $r = new Registry(); // Error: Call to private Registry::__construct()

/**
 * get instance
 */
$r1 = Registry::getInstance(); // "default" instance

$r1->set('key', 'value');

print_r($r1->get('key'));
/**
  value
 */

$r1->set('key1', 'value1');
print_r($r1->get('key1'));
/**
  value1
 */

print_r($r1->getAll());
/**
Array
(
	 [key] => value
	 [key1] => value1
	 )
 */

echo '
'; $r2 = Registry::getInstance('myData'); print_r($r2->getAll()); /** Array ( ) */ $r2->set('key22', 'value22'); print_r($r2->getAll()); /** Array ( [key22] => value22 ) */ # end of file