Archive for category Languages

Flags for PHP

In my last post I wrote about the enumerated type (Enum) for PHP. In C# an Enum can have multiple values when it has the [Flags] attribute. A flags enum can be seen as a bitwise mask which can be used to combine boolean properties of an entity into one single integer property. This might come in handy when filtering on these properties. In this article I show my implementation for a flags enum in PHP and demonstrate the use of it in an example.

Read the rest of this entry »

1 Comment

The enumerated type for PHP

Enum

Whenever a procedure accepts a limited set of variables one could use an enumeration. Enumerations make for clearer and more readable code, particularly when meaningful names are used. A page at MSDN states the benefits of using an enumeration include:

  • reduction of errors caused by transposing or mistyping numbers,
  • simplify changing values in the future,
  • code is easier to read, which means it is less likely that errors will creep into it and/or
  • ensuring forward compatibility. With enumerations, your code is less likely to fail if in the future someone changes the values corresponding to the member names.

Enumerations are a must if your software solution spans across multiple projects and/or if the team you work is rather large. Read the rest of this entry »

1 Comment