I'm working with some pretty attrocious code. Every line contains at least one wtf. I've become kind of numb to them by now. But this one was a perfect argument for coding correctly, and not coming up with "clever tricks". You should never have to "trick" the computer into doing what you want. Coding should be intentional, not magical.
So anyways, I'm working with a script that takes a radius and inserts all of the zip codes within that radius into a database. The new radius is passed through the header as "inputFD[2]", instead of "newRadius" (or something logical like that). Well, the same page (consisting of 10 different files ranging from 300-1200 lines of mostly uncommented code) used in a different context, unbeknownst to me, also passes a list of zipcodes to be inserted into a different DB table through, you guessed it, a header variable called "inputFD[2]" instead of something logical like "zipList".
Shortly after testing (quickly) and launching an update to this page we started getting jobs that would be assigned every zipcode in the entire USA. We were confused at first. I wrote the code that did the assignment, but I had very little knowledge of the insane spaghetti code that I was inserting this code into. I assumed that inputFD[2] was only ever a zipcode radius, and also assumed that the place I was putting the code to do the insert was only ever run when they were actually working with zipcode radii. These are the sort of assumption one has to make when your boss wants something done NOW.
By now you may have realized what happened. There is another view of the page that I had no knowledge of where the user can enter a list of zips and it will be passed through the inputFD[2] variable and parsed by my script as if it were a radius, resulting in the script thinking the job has a radius of "27943,23817,23481,23492,..."(etc, etc, up to 500 zips) and therefor in some cases encompasing the entire universe.
sigh.
Please give your variables a clear name and one purpose. PLEASE.
Oh, and this is the from the same PHP page that was the topic of this post. I could probably fine 100 other gems like this in the code in that page...