- 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
7/$FIRST
Admin
This is in preparation of putting the formula in a database as a string, right?
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
We obviously the programmer was thinking Enterprise-y-ingly toward the future where all those strings are stored in an XML configuration file.
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
"I hate the guy who goes around telling other people how to do their jobs with his so-called security advice. I want something where it looks like he's asking me to break five other coding principles so I can complain about him to management."
Admin
I’d bet that this is a poorly disguised backdoor into the system. Mind you, that’s also my assumption whenever I see “eval” being used anywhere in any language…
Admin
Hmm, does PHP do floating point division on integers or will this truncate the /100? Or does it evaluate the *1.7 first?
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.