PHP继承构造函数没有';行不通
请检查我的问题,我制作了一个脚本,但PHP继承构造函数没有';行不通,php,oop,Php,Oop,请检查我的问题,我制作了一个脚本,但$contractemspal变量不起作用。我想要员工工资,但我有错误。请查收 下面是我的代码:- <?php class baseemp { protected $firstname; protected $lastname; public function getfullname() { return $this->firstname .''. $this->lastname; } public function __
$contractemspal
变量不起作用。我想要员工工资,但我有错误。请查收
下面是我的代码:-
<?php
class baseemp {
protected $firstname;
protected $lastname;
public function getfullname() {
return $this->firstname .''. $this->lastname;
}
public function __construct($first,$last) {
$this->firstname="$first";
$this->lastname="$last";
}
}
class fulltimeemp extends baseemp {
public $monthlysal;
public function monthlysalary() {
$this->monthlysal/12;
}
}
class contractemp extends baseemp {
public $hourlyrate;
public $totalhours;
public function monthlysalaryy() {
$this->hourlyrate * $this->totalhours;
}
public function __construct($hourrate,$totalhoursd){
$this->hourlyrate="$hourrate";
$this->totalhours="$totalhoursd";
}
}
$fulltimeemployee = new fulltimeemp("kannu"," singh");
$contractempsal = new contractemp("400","5");
echo $fulltimeemployee->getfullname();
echo $contractempsal->getfullname();
?>
这是我的代码。请检查并告诉我哪里错了,谢谢
请检查我的问题,我制作了一个脚本,但
$contractemspal
变量不起作用。我想要员工工资,但我有错误。请检查。您需要更新constractemp类的_-construct函数,然后调用父::_-construct
来设置名字和姓氏
<?php
class baseemp {
protected $firstname;
protected $lastname;
public function getfullname() {
return $this->firstname .''. $this->lastname;
}
public function __construct($first,$last) {
$this->firstname="$first";
$this->lastname="$last";
}
}
class fulltimeemp extends baseemp {
public $monthlysal;
public function monthlysalary() {
$this->monthlysal/12;
}
}
class contractemp extends baseemp {
public $hourlyrate;
public $totalhours;
public function monthlysalary() {
return $this->hourlyrate * $this->totalhours;
}
public function __construct($first,$last, $hourrate, $totalhoursd){
parent::__construct($first,$last);
$this->hourlyrate="$hourrate";
$this->totalhours="$totalhoursd";
}
}
$fulltimeemployee = new fulltimeemp("kannu"," singh");
$contractempsal = new contractemp("kannu"," singh", "400","5");
echo $fulltimeemployee->getfullname(); // display kannu singh
echo $contractempsal->getfullname(); // display kannu singh
echo $contractempsal->monthlysalary(); // display 2000
“我出错了”什么错误?您已经完成了哪些调试?抱歉,我没有收到错误,显示为空白屏幕我只想获取员工工资,但没有显示任何内容:(检查错误日志和/或启用错误报告。从我的代码中,您认为这是正确的,好吗?抱歉,您的代码不起作用,再次显示为空白,结果中没有显示员工工资:(我刚刚更新,请看一下。现在,两个函数都显示“kannu singh”。这是您想要的吗?请检查waitWarning:contractemp::setEmployeeFullname()缺少参数1),在第240行的D:\xampp\htdocs\oops\index.php中调用,在第217行的D:\xampp\htdocs\oops\index.php中定义。注意:未定义变量:在第218行的D:\xampp\htdocs\oops\index.php中定义employeeFullName,请更新我的php代码中的所有代码,然后我进行全面检查