构造方法:__construct,析构方法:__destruct
代码示例:
1 <?php 2 class Person 3 { 4 public $name; 5 public $age; 6 public function __construct($name,$age) 7 { 8 $this->name=$name; 9 $this->age=$age; 10 } 11 public function showInformation() 12 { 13 echo "<br/>姓名:".$this->name; 14 echo "<br/>年龄:".$this->age; 15 } 16 public function __destruct() 17 { 18 echo "<br/>释放资源".$this->name; 19 } 20 } 21 $zhangsan=new Person("张三",12); 22 //$temp=$zhangsan; 23 $zhangsan=null; 24 $lisi=new Person("李四",13); 25 $wangwu=new Person("王五",14); 26 ?>
时间: 2024-10-31 19:10:12