嘿,我对 oop 还很陌生,在学习的过程中,我遇到了一个折磨我超过 2 小时的问题。
你能告诉我为什么this-> flavor
没有得到"grape"
价值吗?
<?php
class Product{
public $name = "default-name";
public $price = 50;
public $desc = "default_description";
function __construct ($jemali, $zviadi, $chuuch){
$this->name=$jemali;
$this->price=$zviadi;
$this->desc=$chuuch;
}
public function getInfo(){
return "product name:".$this->name;
}
}
class Soda extends Product {
public $flavor="default flavor";
function __consturct($jemali, $zviadi, $chuuch, $lavor){
parent::__construct($jemali, $zviadi, $chuuch);
$this->flavor=$lavor;
}
public function getInfo(){
return "product name:".$this->name." flavor ".$this->flavor;
}
}
//$shirt = new Product("miriani", 10, "magari");
$soda = new Soda("jemala", 12, "chuchuka", "grape");
//echo $shirt->getInfo();
echo "<br />";
echo $soda->getInfo();
?>
输出是产品名称:jemala 风味默认风味