如何在PHP的非抽象类中声明抽象方法? [英] How to declare abstract method in non-abstract class in PHP?

查看:170
本文介绍了如何在PHP的非抽象类中声明抽象方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class absclass {
    abstract public function fuc();
}

报告:

PHP致命错误:类absclass 包含1个抽象方法,必须 因此被声明为抽象或 实施其余方法 (absclass :: fuc)

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?

推荐答案

我认为其余方法实际上是指您要定义的抽象方法(在本例中为fuc()) ,因为可能存在的非抽象方法还是可以的.这可能是一条错误消息,可以使用更好的措辞:在其中显示 remaining 的地方应显示 abstract .

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

...正确实施:

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

...,或者根据您的需要,将整个类抽象化:

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

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

这篇关于如何在PHP的非抽象类中声明抽象方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆