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

后端 未结 7 507
不知归路
不知归路 2020-12-14 14:51
class absclass {
    abstract public function fuc();
}

reports:

PHP Fatal error: Class absclass contains 1 abstract metho

7条回答
  •  无人及你
    2020-12-14 14:59

    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();
    }
    

提交回复
热议问题