它返回的垃圾輸出。我是PHP新手。請幫我解決這個問題。我不想永遠陷入這種困境。我是面向對象編程的新手,所以我無法弄清楚哪裏出了問題和哪裏!爲什麼我這個php代碼出錯了?
<?php
Abstract class Employee {
protected $Fname;
protected $Lname;
protected $dept;
static protected $total= '0';
public abstract function getSalary();
function __construct($f,$l,$d) {
$this->Fname = $f;
$this->Lname = $l;
$this->dept = $d;
self::$total++;
}
public function getFullname() {
return $this->Fname." ".$this->Lname;
}
public function getDept() {
return $this->dept;
}
public static function getTotal(){
return self::$total;
}
}
class FullTime extends Employee {
protected $Annualsalary;
function __construct($s) {
$this->Annualsalary = $s;
}
public function getSalary() {
return $this->Annualsalary/12;
}
}
class Contract extends Employee {
protected $Monthlypay;
function __construct ($s)
{
$this->Monthlypay = $s;
}
public function getSalary() {
return $this->Monthlypay;
}
}
$emp1 = new FullTime("John",'Doe','IT',150000);
$emp2 = new FullTime('J','Doe','sales',130000);
$emp3 = new FullTime('John','D','sales',140000);
$emp4= new Contract('JOHAN','Doe','sales',14000);
echo "Total Employees = ".Employee::getTotal()."<br>";
echo $emp1->getFullname()." | ".$emp1->getDept()." | ".$emp1->getSalary()."<br>";
echo $emp2->getFullname()." | ".$emp2->getDept()." | ".$emp2->getSalary()."<br>";
echo $emp3->getFullname()." | ".$emp3->getDept()." | ".$emp3->getSalary()."<br>";
echo $emp4->getFullname()." | ".$emp4->getDept()." | ".$emp4->getSalary();
?>
輸出
僱員總數= 0
| | 0
| | 0
| | 0
| | JOHAN
能否請您解釋一下您的問題實際上是什麼? –
你真的得到了什麼錯誤? – Imran
我編輯了這個問題。請看看並幫助我 –