PHP Insanity IV
Mark Mzyk | January 28, 2008
You knew that this series wouldn’t be taking a hiatus for too long.
I’m just going to quote Kevin for today’s insanity. In fact, I’m just ripping his entire post, because it’s short and to the point. I’m sure he won’t mind, since I’m the coworker he’s talking about, and I’m linking back to him. You should read his blog, particularly if you want to escape PHP and check out Erlang. I can tell you he’s got some sweet stuff coming down the pipe, although I can’t reveal what it is yet. I’ll leave that to him.
Onto the insanity:
I had a realization helping a co-worker untangle a thorny knot of nested includes in PHP code:
“Nested includes single-handedly recreate what is arguably the worst scoping policy in computing history, dynamic scope.”
The problem we were fighting was that all the variables and state accumulated in the root scope, aka the first script to be executed, was available several scripts away in the leaf scopes, aka the tawdry terminus of the nested includes. Making changes in the root scope, in this case deleting an object creation statement, caused scripts two includes away to fail in a horribly unintuitive manner.
So, when you’re hacking at light speed on the latest gotta-have-it-right-now feature, please take a second and think about your include depth. Be nice to the developers who come after you and don’t nest includes more than two levels deep.