Uncaught Error: Cannot call abstract method (PHP Fatal error) -
i extending abstract class has 2 abstract methods. when try instantiate the child class, following error,
php fatal error: uncaught error: cannot call abstract method getanswer::getanswer()
when comment out getanswer()
in both parent , child things work fine.
php version: 7.0.2 in xampp, running on wondows 8.1.
parent class file app-getanswer-base.php follows
<?php abstract class getanswer{ abstract public function getanswer($username, $questionnaireid, $questionid); abstract public function getanswers($username, $questionnaireid); }
child class file app-getanswer-db-direct.php
follows
<?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` `answerstore`.`answers` join `answerstore`.`participants` b on a.`participantid` = b.`participantid` a.`questionnaireid` = '$questionnaireid' , b.`username`='$username'"; $result = $connection->query($query); $connection->close(); return $result; } }
i think when trying instantiate child class it's calling getanswer()
method parent class (getanswer
) it's working constructor.
try changing method name else.
Comments
Post a Comment