views:

470

answers:

5
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?

A: 

It means that the proper of an abstract class is having at least one abstract method. So your class has either to implement the method (non abstract), or to be declared abstract.

streetpc
A: 

You're being slightly led astray by this error message. In this case, since it is within this class that fuc is being defined, it wouldn't really make sense to implement it in this class. What the error is trying to tell you is that a non-abstract class cannot have abstract methods. As soon as you put an abstract method in the definition of a class, you must also mark the class itself as abstract.

AakashM
A: 

I presume that remaining methods actually refers to the abstract methods you're trying to define, since the non-abstract methods are okay anyway. It's probably a misworded error message.

Álvaro G. Vicario
I agree with **misworded error message**
How is this possibly the answer? The "remaining methods" in this case refers to "fuc", as the error message says, because you've declared it abstract but not declared the class itself abstract. The error message seems to be perfectly worded.
Robert Grant
+1  A: 

See the chapter on Class Abstraction in the PHP manual:

PHP 5 introduces abstract classes and methods. It is not allowed to create an instance of a class that has been defined as abstract. 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
    };
}
Gordon
A: 

My problem was for example like this in PHP :

class Car{
 public function Car(){
 }
 public function equipment(){
  return 'Your car has 3 doors';
 }
}

abstract class AddEquipment extends Car{
 public abstract function equipment();
}

class AirCondition extends AddEquipment{
 private $newcar;
 private function AirCondition(){
  $newcar = $car;
 }
 public abstract function equipment(){
  return '';
 }
}

In Java it was OK to create object like this, but PHP is throwing - Fatal error: Cannot make non abstract method Car::equipment() abstract in class AddEquipment

Anyone know what I am doing wrong here? :/

Internet strani