http://www.phpe.net/articles/398.shtml
看这个

解决方案 »

  1.   

    1.构造函数并在建立一个对象实例时被执行2.析构函数,相反于构造函数. PHP调用它们来将一个对象从内存中销毁给你一个例子
    <?php
    class Counter 

    private static $count = 0; function __construct() 

    self::$count++; 
    } function __destruct() 

    self::$count--; 
    } function getCount() 

    return self::$count; 

    } //建立第一个实例 
    $c = new Counter(); //输出1 
    print($c->getCount() . "
    n"); //建立第二个实例 
    $c2 = new Counter(); //输出2 
    print($c->getCount() . "
    n"); //销毁实例 
    $c2 = NULL; //输出1 
    print($c->getCount() . "
    n"); 
    ?>