Abstract constants in PHP - Force a child class to define a constant

后端 未结 6 1082
清歌不尽
清歌不尽 2020-12-24 00:43

I noticed that you can\'t have abstract constants in PHP.

Is there a way I can force a child class to define a constant (which I need to use in one of the abstract c

6条回答
  •  执念已碎
    2020-12-24 01:37

    PHP Interfaces support constants. It's not as ideal because you would have to remember to implement the interface on every child class so it kind of defeats the purpose partially.

提交回复
热议问题