fork download
  1. <?php
  2. class Base {
  3. private static $cache = array();
  4.  
  5. public function &__get($name) {
  6. $type = get_class($this);
  7. if (!isset(self::$cache[$type])) {
  8. self::$cache[$type] = '';
  9. }
  10. return self::$cache[$type];
  11. }
  12.  
  13. public function __set($name, $value) {
  14. $type = get_class($this);
  15. self::$cache[$type] = $value;
  16. }
  17. }
  18.  
  19. $b = new Base;
  20. $b->cache = 42;
  21. $b2 = new Base;
  22.  
  23. echo $b->cache . "\n"; // 42
  24. echo $b2->cache . "\n"; // also 42
  25. ?>
Success #stdin #stdout 0.02s 25936KB
stdin
Standard input is empty
stdout
42
42