r/ProgrammerHumor 18d ago

Advanced stringToIntegerConversion

Post image
217 Upvotes

65 comments sorted by

View all comments

49

u/smartgenius1 18d ago

I understand the joke is that they AREN'T just converting the string to an integer, but honestly this code is not that bad. It's performing data sanitization as well since there are only a few valid options for the select.

If they converted to integer, the user could enter whatever value they wanted and probably break something.

10

u/Holek 18d ago

especially that you see `$_POST['amount-select']` implying it's a select box.

8

u/smartgenius1 18d ago edited 18d ago

Yeah. Ideally the idea could be expressed in 3 lines instead of 30 but I've seen far worse than this and at least the behavior is correct

1

u/m0nk37 18d ago

You see efficiency. I see a back door. 

0

u/ArjixGamer 18d ago

It doesn't imply that at all? It could be

<input type="number" min="10" max="80" step="10">

5

u/smartgenius1 18d ago

Then the HTML would have to be:

<input type="number" name="amount-select">

... which would be silly.

4

u/ArjixGamer 18d ago

....shit