- 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
If only the signature of the call() function could have given them some sort of clue how to handle this situation...
Admin
This must be fun to debug if you make a typo in $name or provide more than 6 args.
Admin
This is what I call an indicator block. A code block which itself is not a real WTF, but indicates serious design errors and code smell in the whole codebase. This method is relatively clean, well written and does what it needs to do. It's just that no method should ever need to do that.
Admin
Does PHP have an equivalent of Python's splat operator?
Admin
"indicates serious design errors and code smell in the whole codebase"
C'mon, this isn't just PHP, it's WordPress. That's the thing that the die-hard PHP defenders always feel the need to distance themselves from - "oh, modern PHP has come a long way, a good PHP codebase is no longer anything like legacy garbage like WordPress". (All of which is true, but doesn't excuse the fact of using PHP when literally any other language would be better - it may have improved a lot of minor issues but the core is an unfixable nest of WTF. I digress however.)
So WordPress code is especially terrible, particularly that of any custom plugins being used. We should be terrified that that monstrosity powers about 80% of the web.
Admin
Yeah, since PHP 5.6 you can use '...' to accept and provide a variable number of arguments.
Admin
TRWTF is what [doesn't] happen when the application needs to run "call(somename, 1, 2, 3, 4, 5, 6, 7)"
Admin
6 arguments ought to be enough for anybody.
Admin
Going even farther back, PHP has had call_user_func_array (https://www.php.net/manual/en/function.call-user-func-array.php) for about 20 years.
Admin
Before that, there have always been call_user_func() and call_user_func_array() which would have worked even with very ancient versions.
Admin
There's a huge WTF in this. Yes, the bunch of
if
statements could be replaced bycall_user_func_array()
, but the real problem is that it usesreturn
in the loop. So it only calls the method on the first element of$this->objects
that implements the$name
method. I suppose that could have been intended, but I'm skeptical.Maybe the programmer knew about call_user_func_array, but didn't know how to use it to call methods. You use
array($object, $name)
as the function.Admin
It's like stringly typed data - only for functions.
Admin
Regrettably, this is the unthinking PHP programmer's version of the Python splat.
Leaving aside the ridiculous notion that some God Object should regulate the number of arguments passed to a method, when the arguments are already contained in an array, is utterly pointless. Apparently the (ancient) PHP way to do this is:
... which may have been updated in PHP 5.6, and probably updated in even more "recent" versions. (Last time I used PHP was fifteen years ago, and it was 5.6)
If you really, really, have some perverted need to do this, the Python kwargs is the way to go. Which would require $args to be a tuple of (name, value).
I realise that PHP programmers are cargo cult devotees, and that 99% of them are dumb as pet rocks without an owner, and that the other 1% should really be looking for a job that doesn't involve PHP, but seriously. This stuff is not difficult.
Admin
Sorry -- beat me to it.
Admin
Does your function look ugly because it takes 24 parameters? don't worry, there is a simple solution: Make them all global variables, then your function signature is way way cleaner!
(the ancient php 5.6.4 codebase I'm currently fighting against does have a funtion that starts with a list of 14 global variable declarations.)
Admin
Php with version 7 and also with 8 recently did add some good stuff, you can actually work with it nowadays.
But you'd also have to have programmers who know how to use stuff like types properly.
You might wanna at least give it a glance before disregarding the current php versions just because the ancient ones are shit.
P.S.: ancient php is still a better love story than javascript.
Admin
"over-engineering a solution" -- In 1999 (with a little over 20 years under my belt), I was charged with designing a machine control system for IBE/IBD/DLVC. I looked at what had come before, and created a design in C++.... I moved on from that client, but stayed in touch with the people. In the past 20 years, they have expanded the system quite a bit, but very little had to be modified, in fact in 2019 I got a call from the person who now ran the Software department.... They were going to add a new feature that they thought would deeply impact the software... then they dug into a deep part of the "kernel" and found exact instructions and a sample of what they needed to do. They hade budgeted 9 man months, it was done in under a week....
"Over-Engineered"? Or simple due diligence to "the art of maximizing the amount of work not done" when viewed over nearly a quarter of a century....