fork download
  1. <?php
  2.  
  3. class Registry {
  4. private $data = array();
  5. public function get($key){ return (isset($this->data[$key]) ? $this->data[$key] : NULL); }
  6. public function set($key,$val){ $this->data[$key] = $val; }
  7. public function has($key) { return isset($this->data[$key]); }
  8. }
  9.  
  10. abstract class Controller {
  11. protected $registry;
  12. public function __construct($registry){ $this->registry = $registry; }
  13. public function __get($key){ return $this->registry->get($key); }
  14. public function __set($key,$value){ $this->registry->set($key, $value); }
  15. public function __isset($key) { return $this->registry->has($key); }
  16. }
  17.  
  18. class Applications {
  19. private $registry;
  20. public function __construct($Registry){ $this->registry = $Registry; }
  21. public function __get($key){ return $this->registry->get($key); }
  22. public function __set($key,$val){ return $this->registry->set($key,$val); }
  23. // You should implement an __isset() method here
  24.  
  25. public function buildApplication(){
  26. $this->application_page = 'current/page';
  27. $application = new application($this->registry);
  28. $application->index();
  29. }
  30.  
  31. }
  32.  
  33. class Application extends Controller {
  34. public function index(){
  35. echo empty($this->application_page)?'yes':'no';
  36. //Returns Yes
  37.  
  38. $page = $this->application_page;
  39. echo empty($page)?'yes':'no';
  40. //Returns No
  41. }
  42. }
  43.  
  44. $apps = new Applications(new Registry());
  45. $apps->buildApplication();
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
nono