且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以在PHP接口中创建可选方法?

更新时间:2023-02-24 16:37:04

接口指定实现该类的类实现 必须 的方法,您可以'不要跳过一些,尽管您可以创建其他接口.....您可以做的是将您的接口分成几个较小"的接口,并使用实现一个 或更多 的类.例如,根据 PHP文档中的示例#3>

An interface specifies the methods that must be implemented by a class that implements it, you can't skip some, although you can create additional ones..... what you can do is break your interface into several "smaller" interfaces, and have classes that implement one or more of those as needed, as per example #3 in the PHP Docs