Do PHP interfaces have properties?

前端 未结 3 642
后悔当初
后悔当初 2021-02-11 11:45

Do interfaces in PHP have properties, or do they only have methods?

3条回答
  •  佛祖请我去吃肉
    2021-02-11 12:38

    Interfaces in PHP may only contain public method signatures without a method body. They may also contain constants. But that's it. Nothing else.

    See http://www.php.net/manual/en/language.oop5.interfaces.php

    Interfaces are defined using the interface keyword, in the same way as a standard class, but without any of the methods having their contents defined. […] All methods declared in an interface must be public, this is the nature of an interface. […] Its possible for interfaces to have constants. Interface constants works exactly like class constants except they cannot be overridden by a class/interface that inherits it.

提交回复
热议问题