class ShopProduct{
public $title = "default product";
public $producerMainName = "main name";
public $producerFirseName = "first name";
public $price = 0;
function __construct($title,$firseName,$mainName,$price){
$this->title = $title;
$this->producerFirseName = $firseName;
$this->producerMainName = $mainName;
$this->price = $price;
}
function getProducer(){
return $this->producerFirseName . "{$this->producerMainName}";
}
}
class ShopProductWriter{
function write( ShopProduct $shopProduct){//必须是ShopProduct的实例化类,参数提醒
$str = "{$shopProduct->title}:" . $shopProduct->getProducer() . "({$shopProduct->price})";
return $str;
}
}
class Wrong{}
$weiter = new ShopProductWriter();
$weiter->write(new Wrong());
php获得提示,类提醒
最新推荐文章于 2024-05-19 15:44:15 发布