Posted By

ryantxr on 07/30/12


Tagged

php registry


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

th3fallen


php Registry class


 / Published in: PHP
 

This class is used to store global information for general access throughout the application.

  1. class Registry{
  2. static $entry = array();
  3. function set($k, $v){
  4. self::$entry[$k] = $v;
  5. }
  6.  
  7. function get($k){
  8. if ( isset(self::$entry[$k]) ) {
  9. return self::$entry[$k] ;
  10. }
  11. return null;
  12. }
  13. }
  14.  
  15. // Set a value
  16. Registry::set('somevar', 'somevalue');
  17. // Get a value
  18. $somevar = Registry::get('somevar');
  19.  
  20. // Store objects if you want
  21. $pdo = new PDO($dsn, $dbUsername, $dbPassword);
  22. Registry::set('pdo', $pdo);

Report this snippet  

You need to login to post a comment.