码迷,mamicode.com
首页 > Web开发 > 详细

【PHP构造方法和析构方法的使用】

时间:2014-09-13 10:34:14      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:des   winform   style   blog   http   color   io   os   使用   

构造方法:__construct,析构方法:__destruct

代码示例:

bubuko.com,布布扣
 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 ?>
View Code

 

【PHP构造方法和析构方法的使用】

标签:des   winform   style   blog   http   color   io   os   使用   

原文地址:http://www.cnblogs.com/kuangdaoyizhimei/p/3969522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!