DEV Community

Elliot Derhay
Elliot Derhay

Posted on

What's a recent frustrating bug you've had with a crazy simple solution?

Today I spent 1.5 - 2 hours trying to debug an issue I was having with PHPMailer -- or was it my foreach loop, or perhaps a misspelled variable, or maybe that method name was supposed to start with a capital letter...?

Just kidding. The issue is fixed at this point, and I did at least learn something new today.

But I'm sure that cycle of questions is familiar to you. Questions like those seem to always clot together in the mind when something that is broken obviously shouldn't be -- or should it be? At that moment, who knows?

Today's problem -- I thought -- was caused by switching from PHP 5.3.x to 5.6.x for a specific codebase (see edit below).

What ended up being the culprit was the lack of the keyword global at the top of a function that was using global variables. These variables (two of them, it turned out) were not being set within the function.

Lessons learned today

  1. Don't automatically trust your own code. Even if it worked semi-recently, "semi-recently" isn't "now".

  2. Look into language upgrades more often. Rare issues that occur between language versions do still happen, even if they are rare. Since not all projects use the exact same sets of features, looking for possible breaking changes between versions is definitely important.

  3. Lingering confusion is probably worth looking into. After typing all of this, and knowing that the variables suddenly weren't accessible anymore - and looking into it for a little longer -- I'm still not 100% sure that the language upgrade is what caused this issue; it seems that the global keyword was available back in PHP 4 (maybe someone with more experience knows).

Back to the question:

What have you been stuck on for some time that turned out to be unbelievably simply to fix?


P.S. I realize an upgrade from 5.3.x to 5.6.x is fairly "behind the times", but it happens to be where we are on a VPS we use. I do see that changing in the foreseeable future though.

Also, I apologize if my writing is all over the place. While I do look forward to being able to write more, this was only meant to be a quick little post anyway (and it may have even grown beyond that 😅).

Thanks for stopping by to read!


Edit: regarding #3 above, I'm definitely more confused now... A local dev who's used PHP since 5.2 told me without the global keyword, it will always error out.

Top comments (10)

Collapse
 
scottishross profile image
Ross Henderson

A procedure I had running was going backwards, and I simply had two swap two parameters around and the whole the worked as intended.

Collapse
 
jsn1nj4 profile image
Elliot Derhay

Backwards? Wow, that's definitely a new one on me.

Collapse
 
scottishross profile image
Ross Henderson

It was a stupid mistake by myself. Instead of it working out like 4 - 3 = 1, it was doing 3 - 4 = -1.

But it took me roughly 3 months to figure out it was a problem, i.e. when it went into production aha. My testing was showing correct values, but that's because I was faking the math correctly.

It was a learning experience :)

Thread Thread
 
jsn1nj4 profile image
Elliot Derhay • Edited

That reminds me of that post about things we always google. One of mine always seems to be the param order for the callback passed to Array.prototype.map().

Param order can definitely get you. But I'm now glad to have hints in both Atom and VS Code about what the next param is expected to be -- at least if the function is defined in the code, or is a native member of the language.

Thread Thread
 
nektro profile image
Meghan (she/her)

I don’t have a nice pneumonic to help but I realized one day that map, forEach, and a few others all have the same callback Parma order of value, index, array

Thread Thread
 
jsn1nj4 profile image
Elliot Derhay • Edited

I kept flipping index and value (and forgetting about array, honestly). But that order does make a lot more sense since the index and array aren't needed for everything.

Thanks for mentioning that by the way. I guess they would've done that for consistency and ease of use.

Collapse
 
spidergears profile image
Deepak Singh • Edited

We had sidekiq jobs setup to send out emails. We made a few changes to the template one day and then it started.
Some outgoing email had the new email template and some were still using the old template. This baffled everyone on the team, QAs were frustrated too since they could not reproduce it consistently in the QA env. This was supposed to be rolled out the next day, hence a sense of urgency too.

BUG

We had recently setup a new sidekiq jobs server and did not decommission the old one (we planned to use it for another env). The new code was deployed to the new servers. Whenever the old server would pick the job it would send out an email with the old template causing the confusion.

Collapse
 
alchermd profile image
John Alcher

I was writing a unit test for POST requests on an api endpoint and was wondering why no data was being returned. I tried logging the request object and the data expected was being sent back; it was a wild situation that I almost threw the towel in. Apparently, the endpoint was responding with a 204 status code that literally meant NO CONTENT. That's a funny TIL moment for me.

Collapse
 
jsn1nj4 profile image
Elliot Derhay

Ok, I ended up deleting a sentence because I couldn't get strikethrough to work. Turns out I was using the wrong character. 😅

Collapse
 
jsn1nj4 profile image
Elliot Derhay

Oh yeah, those are my favorites (wrong letter case).