Major blow to new search for MH370 as Malaysia explains huge setback
Iconic UK theme park announces two new attractions
Jose Mourinho pinches the NOSE of Galatasaray boss Okan Buruk after Fenerbahce lose feisty Istanbul derby - with Chelsea legend facing another long ban amid chaotic first season in Turkey
Trump shuts major online shopping loophole in blow to bargain hunters as his sweeping tariffs take effect
Budget airline launches ice cream range with some seriously bizarre flavours - we test it out with VERY surprising results
Representative Line: Get Explosive
Sean sends us a one-line function that is a delight, if by delight you mean "horror". You'll be shocked to know it's PHP.
function proget(){foreach($_GET as $k=>$v){if($k=="h"){$GLOBALS["h"]=1;}$p=explode(",",$k);}return($p);} //function to process GET headersBased on the comment, proget is a shorthand for process_get_parameters. Which is sort of what it does. Sort of.
Let's go through this. We iterate across our $_GET parameters using $k for the key, $v for the value, but we never reference the value so forget it exists. We're iterating across every key. The first thing we check is if a key "h" exists. We don't look at its value, we just check if it exists, and if it does, we set a global variable. And this, right here, is enough for this to be a WTF. The logic of "set a global variable based on the existence of a query parameter regardless of the value of the query parameter" is… a lot. But then, somehow, this actually gets more out there.
We explode the key on commas (explode being PHP's much cooler name for split), which implies… our keys may be lists of values? Which I feel like is an example of someone not understanding what a "key" is. But worse than that, we just do this for every key, and return the results of performing that operation on the last key. Which means that if this function is doing anything at all, it's entirely dependent on the order of the keys. Which, PHP does order the keys by the order they're added, which I take to mean that if the URL has query params like ?foo=1&h=0&a,b,c,d=wtf. Or, if we're being picky about encoding, ?foo=1&h=0&a%2Cb%2Cc%2Cd=wtf. The only good news here is that PHP handles the encoding/decoding for you, so the explode will work as expected.
This is the kind of bad code that leaves me with lots of questions, and I'm not sure I want any of the answers. How did this happen, and why are questions best left unanswered, because I think the answers might cause more harm.
[Advertisement] Plan Your .NET 9 Migration with ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
White Lotus star Carrie Coon claps back at Meghan McCain in ugly spat over her support of Trump
Britain's billionaire club revealed: The 55 super-wealthy Brits who appear on the annual Forbes' list of the world's richest people
Counter terror police issue warning to parents to look out for signs their child is at risk of radicalisation online in wake of Netflix show Adolescence
Val Kilmer's ex-wife Joanne Whalley and daughter Mercedes seen for the first time since actor's death at 65
Desperate Hailey Bieber's frantic call for help as 'manic' Justin is now 'not eating, sleeping... and his decline takes grim new twist'
How to challenge a CCJ: 'I overstayed car park by three minutes and ended up with debt marker unknowingly'
How to make a small garden look bigger: These 15 tricks will make the most of a poky outdoor space
HMRC collected a quarter of a BILLION pounds from taxpayers in late penalties in just two years
My son's Sports Direct jacket got lost: Has Evri charged me £53 for a phone call to sort it? CRANE ON THE CASE
Maldon property developer has development site shut down after 'serious' safety breaches
OpenStack delivers ‘Epoxy’ release, which it hopes will unglue more VMware customers
The Open InfraFoundation has delivered a new version of OpenStack named “Epoxy” and thinks it’s an even better option for those seeking a VMware alternative.…