Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been programming in PHP for a long time and I've never ever accidentally used an octal anywhere. Does such a non-problem really need this much attention?


Perhaps you ask a user to enter the month of their CC expiration date, which is shown as 08/14 on their card.

  $v = validated_integer($user_input); // the user input 08
  if($v == 0 || $v === 0) { // let's just be safe
    
    // the Wrong Thing happens
    
  }
This is a contrived example, sure. But you've never checked to see if a user input the number 0? Or a non-zero, positive integer?


I'm not sure what you expect to happen there but the following code always produces "Correct!":

    $user_input = '08';
    $user_input = (integer)$user_input;
    if ($user_input == 8) echo 'Correct!';
    if ($user_input == 0) echo 'Incorrect!';
If you take out the cast, the result is the same. If you change the numbers to '010' and 10 respectively, the result is also "Correct!". There is no weirdness.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: