php5析构函数用法示例
时间:2021-07-01 10:21:17
帮助过:39人阅读
- /*
- * 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析构函数的用法。
|