Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 829459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:53:11+00:00 2026-05-15T03:53:11+00:00

This question bugged me for years now and can’t seem to find good solution

  • 0

This question bugged me for years now and can’t seem to find good solution still. I working in PHP and Java but it sounds like this maybe language-agnostic 🙂

Say we have a standard status reference table that holds status ids for some kind of entity. Further let’s assume the table will have just 5 values, and will remain like this for a long time, maybe edited occasionally with addition of a new status.
When you fetch a row and need to see what status it is you have 2 options(as I see it at least) – put it straight ID values(magic numbers that is) or use a named constant. Latter seem much cleaner, the question though is where those named constants should leave? In a model class? In a class that uses this particular constant? Somewhere else?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:53:11+00:00Added an answer on May 15, 2026 at 3:53 am

    It sounds like what you’re wanting to do is an enumerated value.

    This is a value that has a literal name mapped to a constant value, this would be something like

    Statusone = 1
    Statustwo = 2
    

    Then anywhere in your program you could refrenece statusone which the compiler would see as 1.

    I’m not sure if this exists in php but I’m pretty sure it does in java

    EDIT In response to some comments

    I would typically put enumerated values in some kind of global namespace, or if you only need them when you are using that class spefically you can put them at the class level.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This one has bugged me for the longest time and a great question to
This is a rather basic question, but it's one that's bugged me for awhile.
I know this is not a hell of an useful question but I can't
This has always bugged the hell out of me. Why are lists like this?
I've got models like this: class PledgeItem(models.Model): title = models.CharField(...) usd_amount = models.DecimalField(...) class
I'm maintaining a plugin (implemented as a dll) for a big closed source application.
A couple of summers ago I worked for company that needed an Access DB
Hi Sitepoint wizard people, Say we have an admin application that has multiple users
Right, here's the story: We have had a website for one of our brands

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.