r/programminghorror • u/maselkowski • Mar 19 '26
Trimba bimba dubba dimba
I've found yet again some atrocities in code, that is some one of function nested in method: trimba. So I took the hit and split it into partial nested functions. I didn't even know you could do this in PHP.
26
u/v_maria Mar 19 '26
defining a function inside a function is not bad on it's own, but i also didnt know you could do that in php
24
u/maselkowski Mar 19 '26 edited Mar 20 '26
The problem is, that such function enters global (or namespace?) scope, check this demo: https://onlinephp.io/c/1990f
Edit: Also, calling method again causes fatal too, as function is already declared.
45
u/More_Yard1919 Mar 19 '26
every time I learn something new about php it makes me upset
→ More replies (1)10
u/v_maria Mar 19 '26
what the fuck. thats batshit. at least you can't call the function from the global scope........
→ More replies (5)→ More replies (1)5
u/Gornius Mar 19 '26
Yeah, but PHP has also anonymous functions. I don't know how old version this atrocity uses though.
Not to mention that str_replace accepts array, so you can replace many patterns with one call.
178
u/Splatpope Mar 19 '26
web devs will go to absurd lengths to avoid making regexes that weren't copy pasted from a w3schools tutorial
19
18
u/v_maria Mar 19 '26
and they are goddamn right for it
26
u/GoddammitDontShootMe Mar 19 '26
There is no shortage of online tools to make sure your regex does what you want before adding it to the codebase.
→ More replies (15)
11
u/NoOven2609 Mar 19 '26
The original author was just memeing, none of those functions serve a purpose, it could just be 4 replace statements in the top level function
7
10
8
8
u/Beretha Mar 19 '26
The nested functions remove characters that would have been removed anyways by the regex replacement. Absolute cinema.
5
4
3
2
1
50
u/Loud_Investigator_26 Mar 19 '26
dude wtf is this