Jump to content

poisa

New Members
  • Content Count

    3
  • Joined

  • Last visited

Community Reputation

0 Neutral

About poisa

  • Rank
    Newbie

Profile Information

  • Gender
    Not Telling
  1. Hmm... Interesting ideas. ignace, yours in particular reminds me of Java a bit. I do have a question about it though. In your getOptions() method you are returning strings. Do you see any benefit in doing the following instead? public static function getOptions() { return [static::ACTIVE(), static::INACTIVE(), static::BANNED()]; }
  2. Let's take this status table: id | name ---+------- 1 | active 2 | inactive 3 | banned In this case, I know that this table will not be edited ever, and if it is, it will happen extremely rarely and most likely a status will only be added. Also, the name is basically for when you look at the DB manually as it is never displayed anywhere. Let's say a user table has a status_id field (with a foreign key constraint to the status table, for good measure). Knowing the status of the user by looking at the database is pretty straight forward. But let's go to the code... In PHP it's very obscure to do things like: if ($user->status == 2) { // what the heck is 2? } So I usually do it this way: if ($user->status == User::STATUS_INACTIVE) { // Ah, yes, user is indeed inactive. } The only problem is that it requires me to basically copy the contents of a table in code; anything in the status table I have to create as a class constant. I'm curious to see how people deal with situations like these. I encounter this issue pretty often and would like to know if there are other ways to deal with this in a more elegant way.
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.