平时作业题目 发上来 同学们一起学习
class Goods{
private $Name;
private $Price;
private $Color;
private $type;
private $goods;
private function __construct($Name,$Price,$Color,$type){
$this->Name=$Name;
$this->Price=$Price;
$this->Color=$Color;
$this->type=$type;
}
function getIstance(){
if($goods==null)
$goods=new Goods("面包",3.5,"橙黄","食品");
return $goods;
}
function __destruct(){
echo "清除价格",$this->Price;
}
}
Goods::getIstance();
?>
本文提供了一个PHP类的设计实例,展示了如何定义一个商品类,包括构造方法、获取实例的方法及析构函数。通过此例,读者可以了解面向对象编程中类的基本用法。

1万+

被折叠的 条评论
为什么被折叠?



