代碼運行沒有錯誤,但名字不顯示是為什么?
? <p><?php
class Human
{
public $name;
public $height;
public $weight;
public function eat($food){
echo $this ->name."'s eating ".$food."\n";
}
}
class Player extends Human?
{
}
$jor=new Human("jor","198cm","75kg");
echo $jor ->name."\n";
$jor ->eat("orange");
?>
2016-05-18
你new錯了,要new Player類
<?php
class Human{
public $name;
public $height;
public $weight;
public function eat($food){
echo $this->name."'s eating ".$food."\n";
}
}
class Player extends Human{
function __construct($name,$height,$weight){
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
}
}
$jor = new Player("jor","198cm","75kg");
echo $jor->name."\n";
$jor->eat("orange");
?>
2016-07-14
new ?子類不是父類
2016-05-16
可不可以幫我把代碼直接改好?。课野褬嬙旌瘮?shù)加入Human類里,name也沒出來
2016-05-14
構造函數(shù)加到Human類里面
2016-05-12
? <p><?php
class Human
{
public $name;
public $height;
public $weight;
public function eat($food){
echo $this ->name."'s eating ".$food."\n";
}
}
class Player extends Human?
{
function __construct($name,$height,$weight)
$this->name=$name;
$this->height=$height;
$this->weight=$weight;
}
$jor=new Human("jor","198cm","75kg");
echo $jor ->name."\n";
$jor ->eat("orange");
?>
加了構造函數(shù)還是沒顯示
2016-05-12
你沒寫構造函數(shù),你的數(shù)據(jù)沒有錄進去$jor里面,$jor用的是你定義的類里面的原來的name height weight 就是空的