Thursday, July 4, 2019

How to declare abstract method in non-abstract class in PHP?




class absclass {
abstract public function fuc();
}


reports:




PHP Fatal error: Class absclass

contains 1 abstract method and must
therefore be declared abstract or
implement the remaining methods
(absclass::fuc)




I want to know what it means by implement the remaining methods,how?


Answer



I presume that remaining methods actually refers to the abstract methods you're trying to define (in this case, fuc()), since the non-abstract methods that might exist are okay anyway. It's probably an error message that could use a better wording: where it says remaining it should say abstract.




The fix is pretty straightforward (that part of the error message is fine): you need to change this:



abstract public function fuc();


... into a proper implementation:



public function fuc(){
// Code comes here
}



... or, alternatively and depending your needs, make the whole class abstract:



abstract class absclass {
abstract public function fuc();
}

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...