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() . "<br>n"); //建立第二个实例
$c2 = new Counter(); //输出2
print($c->getCount() . "<br>n"); //销毁实例
$c2 = NULL; //输出1
print($c->getCount() . "<br>n");
?> 当你新建了一个实例,内存会被准备来存储所有属性. 每个实例有自己独有的一组属性. 但方法是由该类的所有实例共享的。







