Skip to content
crussell52 edited this page Jun 11, 2014 · 3 revisions

php-enum

This project is an Enumeration implementation for PHP which is based on the Java Enum data type.

Normally, I don't try to make force one language's constructs into a different language. However, in my time with Java I have grown to appreciate their Enum data type. I believe the functionality offered is significant enough to warrant a php implementation.

I feel it's important to note that, while the implementation of php-enum is of my own design, the patterns and concepts behind it are based heavily on the Java Enum data type. In my time with Java, I've found them to be very good at solving a specific problem. I can not take credit for the ideas behind many of the features that are built into this implementation. For more information on the Java data type, please look here: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

Why?

I think the "why" is always important. After all, I didn't wake up one morning and say, "Hey! Let's take a Java construct and cram it into PHP"...

In software development a list of available values is inevitably necessary. These are often represented as class constants such as this:

class Colors
{
  const RED = 1;
  const BLUE = 2;
  ...
}

Often, this is sufficient but there are some limitations of this approach.

In the example of colors, it is obvious that red is red and blue is blue. That immutable nature of colors suggest that a constant is a good fit.

However, there is much more to a color than the "identifiers" that constants can offer. Each color has an immutable red, green, and blue value. Trying to represent this complex, constant structure with traditional constants is impractical if not infeasible. This is where php-enum comes into play. An Enum can be described as:

"A finite set of values, known prior to runtime, which are each represented by a complex structure comprised SOLELY of constant values"

This project strives to provide a way to solve for this every-day concept.

Clone this wiki locally