Person
クラスを作成してからStudent
クラスに拡張しました。 Student
オブジェクトのメソッドを呼び出すと、期待どおりに機能しません。PHPで継承クラスが正常に動作しません
は、ここでそれが唯一のPersonDetail()
を印刷しますが、教育の標準、対象者との料金のような完全な情報を印刷していない私のコード
class Person{
static public $IsAlive;
public $FirstName;
public $LastName;
public $Gender;
public $Age;
static public $total_person = 1;
static public $type;
function __construct($FirstName,$LastName,$Gender,$Age,$IsAlive,$type=""){
self::$IsAlive = $IsAlive;
if(self::$IsAlive === TRUE){
echo "<strong>Person Number#" . self::$total_person++ . "</strong> details are given below: <br />";
$this->FirstName = $FirstName;
$this->LastName = $LastName;
$this->Gender = $Gender;
$this->Age = $Age;
self::$type = $type;
}else{
echo "This Person is not longer available <br />";
}
}
function PersonDetail(){
if(self::$IsAlive === TRUE){
echo "Person Name: " . $this->FirstName . " " . $this->LastName . "<br />";
echo "Person Gender: " . $this->Gender . "<br />";
echo "Age: " . $this->Age;
}
}
}
class Student extends Person{
public $standard = "ABC";
public $subjects = "ABC";
public $fee = "123";
function StudentDetail(){
if(parent::$type === "Student"){
return parent::PersonDetail();
echo "Education Standard: " . $this->standard;
echo "Subjects: " . $this->subjects;
echo "Fee: " . $this->fee;
echo parent::$type;
}
}
}
$Hamza = new Student("Muhammad Hamza","Nisar","Male","22 years old",TRUE,"Student");
$Hamza->StudentDetail();
です。
は、ここで私は同様にそれ以下のStudentDetail()
出力を確認する必要が私の出力
Person Number#1 details are given below:
Person Name: Muhammad Hamza Nisar
Person Gender: Male
Age: 22 years old
です。何が間違っていて、どのように修正するのですか?
return parent :: PersonDetail();を設定しようとしますか?関数の最後の行にStudentDetail()または戻り値を削除しますか? – dimis283