<?php
/*PHP析构方法的用途非常大

?* WEB开发笔记 www.chhua.com 每日练习之PHP析构方法的使用
?*/
/*
?*/

class classTest {
?private $name;
?private $age;
?private $id;
?function __construct($name,$age) {
??$this->age=$age;
??$this->name=$name;
?}
?
?function setId($id){
??$this->id=$id;
?}
?
?function __destruct(){//析构方法,当销毁对象时执行
??if (!empty($this->id)){
???echo “Name:”.$this->name.”<br>”;
???echo “Age:”.$this->age.”<br>”;
???echo “ID:”.$this->id.”<Br>”;
???
??}
?}
}

$user=new classTest(“www.chenhua.com”,”100“);
$user->setId(101);
unset($user);//销毁对象
?>