Rumah >pembangunan bahagian belakang >tutorial php >php学习类的使用
<?phpclass MyPc { var $hpf; public $name; /*function MyPc ($name='') { $this->name=$name; }*/ function __construct($name=''){ $this->name=$name; } function newfu(){ echo "this is ok!"; } function game () { return $this->name."play games!<br>"; } function compute () { return "编程!"; } function __destruct(){ echo "<br>------------------------".$this->name; }}$pc1=new MyPc("家用电脑");$pc2=new MyPc("公司电脑");$pc3=new MyPc("");echo $pc1->game();$pc1=null;echo "<br>".$pc2->name;?>