Click Upvote Click Upvote - 15 days ago 6
PHP Question

How to implement Enum like functionality in PHP?

How can Enum-like functionality (as provided in Java and other high level languages) be used in PHP? I know PHP doesn't allow you to create enums currently, but what's the closest one could get?

Answer

Using const, perhaps.

class SomeClass {
    const FIRSTVAL = 1;
    const SECONDVAL = 2;
};
Comments