Advertisement
Guest User

Untitled

a guest
May 11th, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1.  
  2.  
  3. abstract class FooBase{
  4.  
  5.   public function __get($name){
  6.     $getter = 'get'.ucfirst($name);
  7.     if(method_exists($this, $getter)) return $this->$getter();
  8.     throw new Exception("Property {$getter} is not defined.");
  9.   }
  10.  
  11.   public function __set($name, $value){
  12.     $setter = 'set'.ucfirst($name);
  13.     if(method_exists($this, $setter)) return $this->$setter($value);
  14.     throw new Exception("Property {$setter} is not defined.");
  15.   }
  16.  
  17.   public function __call($name, $arguments){
  18.     $caller = 'call'.ucfirst($name);
  19.     if(method_exists($this, $caller)) return $this->$caller($arguments);
  20.     throw new Exception("Property {$caller} is not defined.");
  21.  
  22.   }
  23.  
  24. }
  25.  
  26. class Foo extends FooBase{
  27.  
  28.   static $instance;
  29.   private $data;
  30.  
  31.   private static
  32.     $yql = 'https://query.yahooapis.com/v1/public/yql?q=';
  33.  
  34.   public static function app(){
  35.     if(!(self::$instance instanceof self)){
  36.       self::$instance = new self();
  37.       self::app()->data = 'somedata';
  38.       // ...
  39.     }
  40.     return self::$instance;
  41.   }
  42.  
  43.   // ...
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement