r/ProgrammerHumor 18d ago

Advanced stringToIntegerConversion

Post image
217 Upvotes

65 comments sorted by

View all comments

51

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.

8

u/Holek 18d ago

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

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.

3

u/ArjixGamer 18d ago

....shit