Guest User

Untitled

a guest
Jan 17th, 2011
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. class A{
  7.     protected static $instance = null;
  8.  
  9.     public static function getInstance(){
  10.         if(self::$instance === null)
  11.             self::$instance = new self();
  12.         return self::$instance;
  13.     }
  14.  
  15.     public function show($param){
  16.         echo 'Show '.$param.chr(10);
  17.     }
  18.  
  19.     public function __destruct(){
  20.         echo 'Destruct '.__CLASS__.chr(10);
  21.     }
  22. }
  23. class B extends Mysqli{
  24.     public function __destruct(){
  25.         A::getInstance()->show(__CLASS__);
  26.         echo 'Destruct '.__CLASS__.chr(10);
  27.     }
  28. }
  29. class C{
  30.     protected static $class = null;
  31.  
  32.     public static function attachClass(&$class){
  33.         self::$class = $class;
  34.     }
  35.    
  36.     public function __destruct(){
  37.         A::getInstance()->show(__CLASS__);
  38.         echo 'Destruct '.__CLASS__.chr(10);
  39.     }
  40. }
  41.  
  42. $a = A::getInstance();
  43. $b = new B();
  44. $GLOBALS['d'] = $b;
  45. // or
  46. C::attachClass($b);
  47. $c = new C();
  48. ?>
RAW Paste Data