我正在擴展具有兩種抽象方法的抽象類。 當我嘗試實例化的子類,我得到以下錯誤,未捕獲錯誤:無法調用抽象方法(PHP致命錯誤)
PHP Fatal error: Uncaught Error: Cannot call abstract method GetAnswer::GetAnswer()
當我註釋掉兩個父母和孩子的事情GetAnswer()
做工精細。
PHP版本:7.0.2在XAMPP中,運行在Wondows 8.1上。
父類文件app-的getAnswer-base.php如下
<?php
abstract class GetAnswer{
abstract public function GetAnswer($Username, $QuestionnaireID, $QuestionID);
abstract public function GetAnswers($Username, $QuestionnaireID);
}
兒童類文件app-getAnswer-db-direct.php
如下
<?php
require_once 'config-db-login.php';
require_once 'app-getAnswer-base.php';
class GetAnswer_SQLSelect extends GetAnswer {
public function GetAnswer($Username, $QuestionnaireID, $QuestionID){
return null;
}
public function GetAnswers($Username, $QuestionnaireID){
$connection = new mysqli(dbLogin::$db_hostname, dbLogin::$db_username, dbLogin::$db_password, dbLogin::$db_database);
if ($connection->connect_error) die($connection->connect_error);
$query = "SELECT `QuestionID`, `Answer` FROM `answerstore`.`answers` AS a JOIN `answerstore`.`participants` AS b ON a.`ParticipantID` = b.`ParticipantID` WHERE a.`QuestionnaireID` = '$QuestionnaireID' AND b.`Username`='$Username'";
$result = $connection->query($query);
$connection->close();
return $result;
}
}
顯示引發錯誤的調用的代碼。 – Tschallacka
@MichaelDibbets,是'$ getAnswers = new GetAnswer_SQLSelect();' – Gamaka