/* * to change the template for this generated file go to * window - preferences - phpeclipse - php - code templates */ class student{ //属性 private $no; private $name; private $gender; private $age; private static $count=0; function __construct($pname) { $this->name = $pname; self::$count++; } function __destruct() { self::$count--; } static function get_count() { return self::$count; } } $s1=new student("tom"); print(student::get_count()); $s2=new student("jerry"); print(student::get_count()); $s1=null; print(student::get_count()); $s2=null; print(student::get_count()); ?> 复制代码 以上实例展示了php5析构函数的用法。