- 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
And then they abbreviate month to "M" in the function name, while spelling out "name to number" in full. That's got to be a frist.
Admin
Frist comment about the screwy comment. It says it "returns month name '01'", which is accidentally correct.
Addendum 2025-01-16 06:39: Never mind, wrong on both counts. As I was going to originally say, the comment is just wrong.
Admin
It's just a very sad "April's Fool" joke.
I can't think of anything else.
Admin
The copypasta machine also failed to change the parameter name to MnumberToMname as well as all the other failures in that function….
Admin
the number to name conversion will not work for a very different reason: the name of the parameter passed into it is not the name they're using to check the month number. I don't remember if this triggers an undefined variable error in php or will simply return the input parameter in this particular case.
Admin
Maybe it's not in the original code, but MnumberToMname should have $mnum as the input parameter, but instead it's $mname.
I also like the comment: //takes month number '01' and returns month name '01'
Admin
The real WTF is not using an IDE. Is there an IDE for PHP?
Admin
Jetbrains PHPStorm.
Admin
"Is it object-oriented or more procedural?" - "Yes."
Admin
Sometimes it feels like it is January forever in the north.
Admin
boy I sure hope they never have to run this in a non-English locale with different month names
Admin
oh boy, I would say they are in for some real octal pain.
Admin
'octal pain' =~ s/o/re/; I presume you meant :)
Yazeran
Admin
No, I mean the 08 and 09 interpreted as octal with their leading 0.
Admin
I thought September was the endless month?
Admin
I'll bet the broken function is never actually used. Even if they don't have unit tests, surely this bug could not have gone unnoticed.
Admin
Maybe they only test in January?
Or maybe this is only used in one report that only runs in January?
Admin
Looks like they first wrote first version and then CP for the other way left job half finished...
Admin
Sure, it's called
vim
andNotepad++
.Admin
The function comment sums it all up:
That's all we need to know there's really bad code ahead. Whoever even writes this is clearly not paying attention.
Admin
Come on! Isn't everyone using MS Code nowadays?
Admin
it's called 'rm'
Admin
Depends on the context. I presume you're thinking of either https://en.wikipedia.org/wiki/Eternal_September or to folks referring to Mastodon (or possibly the Fediverse writ large) having its own starting in September 2022. But there's also https://ismarchoveryet.com and I'm sure there are others I don't know about.
Addendum 2025-01-16 13:53: "or to folks" should have been "or of folks."
Admin
... every now and then I have a bit of imposter syndrome, where I wonder if I'm actually a 'good enough' programmer ... then I see sh!t like this ...
Admin
I guess "writing the constant first in a comparison" is one of those "tell me you've learned the hard way without saying you've learned the hard way" things. (Or you could be Guido and have statements that aren't functions-that-return-void. (And yes I know there's := in Python now.))
Admin
Yeah, Intellij WebStorm should do that. No excuse for this shit.
Admin
Ref:
Or it's simply a coding standard where you once worked. I still think it looks awkward, but I acknowledge it's a goof-reducer. And dev needs all the goof-reducing tactics it can muster.
Admin
It may work in PHP7 but will trigger a warning in PHP8, as they are usually set up.
Admin
so based on the comment, this is the part of this sample of code that does what it claims. We all know we can trust comments to be accurate....
Admin
or at least the "returns" part of the comment is accurate
Admin
a sort of wtf on this is that there are websites where comments are input and shown in separate display from the original page.. so to add a comment, one has to keep a bundle of detail in mind.
why can't we just scroll up and down to either read all the comments while still seeing the page text, or add a comment while also still seeing that text or image?
Admin
There's no default in case none of the comparisons match. So in the first function (the only one that could ever work!) if someone misspelled the month name or used a non-English spelling (which should be errors, but there's no error handling), it could return either an empty string or any random string, depending on whether PHP initializes local variables or just picks up whatever data was in the location for $mnum.
And the second function has multiple layers of failure. Correct the input parameter, and the first 'if' statement changes it to "01". Unless PHP is even weirder than 'c', this is after the comparison, so it never matches any input but "01", and the output is either "" or a random string. Then there's the foul-up for April. Finally, there's no error handling or default; an input of "1" instead of "01", won't match and won't indicate anything is wrong.
Admin
I'm guessing "MnumberToMname" isn't actually used anywhere...
Admin
Since there are no else branches, what happens with invalid function arguments? I guess I'm lucky for not knowing php.
Admin
Right click and then "Open Link in new tab" is your friend.