Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 6
    class Foo implements DaysOfWeek { } and then Foo::Sunday ... what? Commented Apr 4, 2013 at 10:08
  • 3
    Author of question asks for a solution for two things: namespace and auto-completion by IDEs. As the top-rated answer suggested, the easiest way is by using class (or interface, which is just a matter of preference). Commented Sep 11, 2013 at 15:02
  • 6
    interfaces are used to enforce class implementation integrity, this is outside the scope of an interface Commented Dec 22, 2015 at 15:17
  • 3
    @user3886650 Interfaces can and were/are used in Java to keep constant values. So you are not forced to instantiate a class only to get constant values and any IDE offers code completion on them. Also if you create a class that implements that interface it will inherit all those constants - quite handy sometimes. Commented Sep 16, 2016 at 8:26
  • @user3886650 True, but in PHP, interfaces can have constants. Additionally, these interface constants cannot be overridden by implementing classes, or their children. In effect, this is the best answer in terms of PHP, because anything that can be overridden isn't truly functioning like a constant should. Constant should mean constant, not sometimes (even though polymorphism can be useful at times). Commented Sep 11, 2018 at 3:55