Answer the question
In order to leave comments, you need to log in
What is the best way to override parent class method?
Good day.
The other day I tried to write my own "engine", and when writing classes, I ran into the following problem.
Strict standards: Declaration of User::isExists() should be compatible with that of GlobalClass::isExists() in С:\...\mytest\lib\user_class.php on line 31
The parent and child class names are absolutely correct. The only thing I read is that you need to somehow additionally override the method, that is, the one I wrote
public function __construct($db) {
parent::__construct("users", $db);
}
require_once "global_class.php";
class User extends GlobalClass {
public function __construct($db) {
parent::__construct("users", $db);
}
public function isExists($login) {
return $this->isExists("login", $login);
}
abstract class GlobalClass {
private $db;
private $table_name;
protected $config;
protected $valid;
protected function __construct($table_name, $db) {
$this->db=$db;
$this->table_name=$table_name;
$this->config=new Config();
$this->valid=new CheckValid();
}
....
protected function isExists($field, $value) {
return $this->db->isExists($this->table_name, $field, $value);
}
Answer the question
In order to leave comments, you need to log in
What exactly do you not understand in the phrase
It can be interpreted as
the definition of the User::isExists() method must not differ from GlobalClass::isExists()
that is, you break the interface, your method in the class of the heir obviously does something that is not what is required of it.
Learn the principles of OOP and GRASP (you can use video lectures, here you need someone to explain).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question