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?
Abstract method declarations are only permitted in abstract classes. public abstract void MyMethod(); The implementation is provided by a method override, which is a member of a non-abstract class. It is an error to use the static or virtual modifiers in an abstract method declaration.
A normal class(non-abstract class) cannot have abstract methods. In this guide we will learn what is a abstract class, why we use it and what are the rules that we must remember while working with it in Java. An abstract class can not be instantiated, which means you are not allowed to create an object of it.
An abstract class can contain abstract as well as non abstract methods.
Abstract classes and methods are when the parent class has a named method, but need its child class(es) to fill out the tasks. An abstract class is a class that contains at least one abstract method. An abstract method is a method that is declared, but not implemented in the code.
See the chapter on Class Abstraction in the PHP manual:
PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract. Methods defined as abstract simply declare the method's signature - they cannot define the implementation.
It means you either have to
abstract class absclass { // mark the entire class as abstract abstract public function fuc(); }
or
class absclass { public function fuc() { // implement the method body // which means it won't be abstract anymore }; }
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 more precise wording: where it says remaining it could have said 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With