What is the purpose of creating short variable names?

Discussion in 'PHP' started by Mitchell, Jul 9, 2010.

  1. #1
    if (isset($_POST['description'])) $descp = $_POST['description'];

    Thanks.
     
    Mitchell, Jul 9, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    There isnt really a purpose, its actually a waste, but it depends on what you are doing with it.

    If your doing any kind of checking on it - which with user entered data you almost always will, you might be passing it into other functions, objects, and so forth, so to keep track of it (readability) it is often easier to assign it to a meaningful variable - espcially true on forms that are multi-submit.

    what context are you using it in?
     
    lukeg32, Jul 9, 2010 IP
  3. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #3
    It really depends on what you are using it for, the circumstance, etc. On the other hand, it depends on the programmer. In your example, I would definitely assign a short variable name to it because $descp is easier to read/understand than $_POST['description'].
     
    Rainulf, Jul 9, 2010 IP
  4. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I am using it in a form.

    I thought maybe changing the name might make it difficult for hackers.
     
    Mitchell, Jul 9, 2010 IP
  5. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    It doesn't because they can't even see your source code.

    Just be careful when you code, make sure that people can access only what they are supposed to access.. Be mindful of your techniques and frequently check PHP.net for any possible vulnerability in your codes.
     
    Rainulf, Jul 9, 2010 IP
  6. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I create short var names because they are easier to work with and normally more descriptive.
     
    Imozeb, Jul 9, 2010 IP
  7. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for the input.
     
    Mitchell, Jul 9, 2010 IP
  8. sickness01

    sickness01 Member

    Messages:
    57
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #8
    i do the same thing as Imozeb, its easier to do like, $desc = $_POST['description'];, then wherever i need that, put $desc rather than having to put in $_POST['description']; again each time
     
    sickness01, Jul 11, 2010 IP