php Registry class


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.