随笔 - 78  文章 - 25  trackbacks - 0
<2009年6月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿

随笔分类(75)

随笔档案(78)

相册

实用Links

我的Links

搜索

  •  

积分与排名

  • 积分 - 111830
  • 排名 - 519

最新评论

阅读排行榜

评论排行榜

构造函数:constructor
析构函数:destructor

在php5.1中,构造函数统一命名为:
function __construct(){
    #函数体
}

析构函数统一命名为:
function __destruct(){
    #函数体
}

注意,construct和destruct之前有两个下划线,不是一个
下面给出一个构造函数的示例:
<?php
    class Car{
        private $color;
        private $size;
        private $price;
        function __construct(){
            $this->color="red";
            $this->size=4;
            $this->price=30000;
        }

        public function display(){
            echo $this->color."<br>";
            echo $this->size."<br>";
            echo $this->price."<br>";
        }
    }
    $car=new Car();
    $car->display();
?>



posted on 2009-06-28 09:53 期待明天 阅读(269) 评论(0)  编辑  收藏 所属分类: PHP

只有注册用户登录后才能发表评论。


网站导航: