構(gòu)造函數(shù):constructor
析構(gòu)函數(shù):destructor
在php5.1中,構(gòu)造函數(shù)統(tǒng)一命名為:
function __construct(){
#函數(shù)體
}
析構(gòu)函數(shù)統(tǒng)一命名為:
function __destruct(){
#函數(shù)體
}
注意,construct和destruct之前有兩個(gè)下劃線,不是一個(gè)
下面給出一個(gè)構(gòu)造函數(shù)的示例:
<?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
期待明天 閱讀(303)
評(píng)論(0) 編輯 收藏 所屬分類(lèi):
PHP