News Feed
Jobs Feed
Sections




News Archive
Lee Davis' Blog:
The enum conundrum
July 06, 2012 @ 11:56:52

In a new post to his blog Lee Davis describes the enum conundrum - what's the right solution for effectively using ENUM-type fields in your data?

So a user signs up and I want to store a status that reflects their account, or at least an identifier representing that status. Their account could be active, disabled (temporarily), pending approval or maybe deleted. Should I use an enum? I've heard they're evil. Maybe having a reference table with statuses would be better? But now I have to manage a separate table just for that one snippet of data, is that overkill? Could I maybe use that status table for other entities? Or, could I instead just use an integer and reference it on the code level? What is the right solution?

He presents three of the most common situations he's seen for people using enums in the application:

  • "I used enums all over the place" (maintenance between code and DB values)
  • "use a reference table"
  • "I could use a class constant to represent the enum" (enforced in the app)

Of the three, he suggests the third as the option with the most advantages. Not only does it make it simpler to get the allowed values for the field, but you're also more flexible in the kinds of validation you can do on the values.

0 comments voice your opinion now!
enum conundrum reference table constant maintenance


blog comments powered by Disqus

Similar Posts

Jani Hartikainen's Blog: What would make template engines actually useful?

Ben Ramsey's Blog: Undefined Constant Is a String?

Ivo Jansch's Blog: System.out.print in PHP

Zend Developer Zone: A little fun with the average tech salaries as reported by dice.com

Sebastian Bergmann\'s Blog: PHP - kurz & gut (Pocket Reference Update)


Community Events











Don't see your event here?
Let us know!


framework rest usergroup podcast conference series release interview database functional community development language example phpunit introduction zendframework2 symfony2 testing opinion

All content copyright, 2013 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework