2
我正在嘗試編寫類以在我的技能測試中顯示一些人。其中一個問題如下:PHP類設計問題
顯示孩子如何稱呼父母的方法。顯示重載如何工作。指示類變量的語法。
我想我得到了大部分的問題做,但不知道是什麼指示類變量的意思 ...有人能解釋一下我的語法?非常感謝!
Class Phone{
function __construct(){
echo "This is the constructor";
}
protected function feature(){
echo "Communication <br>";
}
}
Class CellPhone extends CordlessPhone {
private $brand;
function __construct(){
echo "<p style='color:red;'>Cell phone feature:</p>";
}
function __set($b, $value){
if($value=="Apple"){
$this->brand=$value." is awesome!";
}elseif($value=="LG"){
$this->brand=$value." is nice";
}else{
$this->brand="We only accept Apple and LG";
}
}
function __get($brand){
return "The brand: ".$this->brand."------";
}
public function feature(){
parent::feature();
echo "Play music<br>";
echo "Surf internet<br>";
}
}
Class CordlessPhone extends Phone {
function __construt(){
echo "<p style='color:red;'>Cordless phone feature:</p>";
}
public function feature(){
parent::feature();
echo "Cordless<br>";
echo "Use Battery<br>";
}
}
$phone=new CellPhone();
$phone->feature();
$phone->brand="LG";
echo $phone->brand;