- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
1.7 percent, obviously
Admin
No Magic Numbers? Check.
Easy devaluation of rewards points? Check.
No magic function symbols? Check.
Well documented way of devaluating rewards points? Oops, missed that one. But it should be easy, once figured out.
No runtime eval statements? Oops, missed that one.
Overall intent comment? Oops, missed another one.
Admin
Oh, and depending on how that $points value gets set (of if php has a notion lilke perl taint mode):
Remote code execution vulnerability? Check
Admin
Perhaps predecessor recently converted to PHP from COBOL?
Admin
My guess: points is a string, or possibly a string. The coder didn't know about automatic string-to-number conversion or heard that relying on it was bad. They also didn't know how to explicitly convert or believed that it was also bad, so they wrote this code that worked and committed it.
Admin
I know that COBOL has been described as a "bondage and discipline" language, but doing the calculation that way in COBOL would be equally WTF-level perverse.
Admin
I feel somehow worried that the ';' at the end of the string passed to eval should be necessary. it just makes it seem more wrong (NB I don't know php or how the eval statement works, so it might be - it's just that - it makes it feel wronger).
Admin
The argument to
eval()
is PHP statements to execute, not an expression (it's analogous to Pythonexec()
). Notice that it begins withreturn
. So the;
at the end is indeed required.The code works, it's just wrong in principle.
Admin
My first impression was that this is a coder who learned / saw somewhere how to use eval, and that's about the sum of their knowledge about PHP. A problem looks like a nail to their eval-hammer.
Admin
IANA a PHP coder.
At least they avoided assembling the string for
eval()
using PHP's moral equivalent of C'ssprintf()
or C#'sString.Format()
. That would have made this mess oh so much more deliciously crunchy.