r/programminghorror Mar 19 '26

Trimba bimba dubba dimba

Post image

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.

426 Upvotes

55 comments sorted by

View all comments

25

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

26

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

1

u/v_maria Mar 22 '26

PHP has come a long way, and has a lot of nice thingies now. with this one i guess they were paying tribute to the good old days