Get Weather - Step 6 - More encapsulation - controlling access


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



Copy this code and paste it in your HTML
  1. //dealing with encapsulation....
  2. class MemCache{
  3.  
  4. private $mem;
  5.  
  6. public function MemCache(){
  7. //some intitialization here...
  8. $this->mem = array();
  9. }
  10.  
  11. public function get($key){
  12. if (!array_key_exists($key, $this->mem))
  13. return $this->mem[$key];
  14.  
  15. //else
  16. echo "Huston we have a problem!";
  17. }
  18.  
  19. public function set($key, $val){
  20. if (array_key_exists($key, $this->mem))
  21. echo "Huston...just to let you know that an override occurs here to $key with val: $val";
  22.  
  23. $this->mem[$key] = $val;
  24. }
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.