- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- 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
Edit Admin
Frist off, I adore the way that
$varNamePrefix
contains a suffix.Edit Admin
What about using
grpID
variable as an index for theuser_Arr_PREFIX
?Edit Admin
Maybe the dev didn't like the s-word?
It's a bit odd to have that type of code dynamically generated - are they trying to ruin their cache performance or is it simply over engineered code. Ah, questions, questions :-)
Admin
Yesterday was foreshadowing, today is the payoff.
Admin
It's never occurred to me before that one might need syntax colouring to identify which language a particular bit of text is in. You might need to be a mantis shrimp to make sense of it though.
Admin
No. Just no. Don't do that kind of mix of PHP and JS.
Now that's mysterious. So that dev was an evil genius after all.
Tbh, generating JS in PHP is not a completely absurd idea, BUT only in the case of a PHP-to-JS transpiler. It doesn't make sense to just generate that JS code on-the-fly like that otherwise.
Edit Admin
Mixing PHP and JavaScript is like mixing solid waste and liquid waste. You need to flush them both down the toilet.
Admin
Sometimes writing from the DB as JS data in the HTML you output is correct. Not how it's done here, of course, but if it's static data that the current request has loaded anyway, it may make sense. But if it's more than a couple of variables (say, you want to populate user's display name, userid, and a CSRF token) then even writing it into the HTML you should probably separate data and code (e.g. if using django, the json_script filter)
Edit Admin
It's not unreasonable to have PHP generate a JS array rather than fetching it with AJAX. But the right way to do this is to build the entire array in PHP, then use
rather than generating lots of assignments.
This also ensures that special characters are properly escaped.
Admin
When your tool is a template processor, every problem looks like concatenation.
Admin
What was it Dijkstra said about APL: "A mistake carried through to perfection … the language of the future for the techniques of the past." If you fell through a time warp to 2005, when JSONP didn't exist and XHR wasn't portable, you might think this was awfully clever, or or at least cleverly awful.
Admin
To be honest, I wrote something similar to this (maybe even nested array) around 1997 (yes, PHP was around there already and you did not have to think about register_globals being on or off since it was just there). While Netscape 3 supported JavaScript and arrays, it did not support array literals. On the other hand it did not support dynamic DOM manipulation either, so everything you could do with such arrays was work with document.layers (to make a flying mouse cursor clock) or use text input fields with border=0 to output stuff. IE3 supported DOM manipulation but no layers. Not sure about array literals. And yes, I used that idiom even some years later, because it just worked.
When the code in question is equally old, no wonder that it still works. You had to code really carefully in these days (I already mentioned register_globals was on all the time, so every uninitialized variable was a potential security issue), and I have the impression that the resulting code was more solid than typical fast-written code today is.
Edit Admin
Whilst looks like a god-awful mess, I can understand the impetus to do it. The really hard bit is writing it with suitable abstractions so that the core logic isn't hard to read.