Jump to content

Recommended Posts

I just spent 20 minutes swearing at my computer. This is one of the most annoying and hard to find bugs ever:

 

function dateToSQL($m, $d, $y, $h=0, $m=0, $s=0){
	if($h || $m || $s) return "$y-$m-$d $h:$min:$s";
	else return "$y-$m-$d";
}

 

See the error? It's that $m for month and $m for minute are the same. Why doesn't PHP throw an error? I have no fucking idea, but it probably should, since it would make no sense to ever intentionally do this. Since the function is so simple, I just first thought it was a problem with the query after it, then with the code before it. Then I thought that 07 was somehow getting converted into the int 0 because of the leading 0....

 

Just one of those nights...

 

Link to comment
https://forums.phpfreaks.com/topic/206249-hard-to-find-bug/
Share on other sites

Surely your code was issuing an E_NOTICE ("Undefined variable: $min ...") due to the use of the $min variable which had not been defined.  I'd say that would point out the "bug" pretty darned quickly.

 

It was return "$y-$m-$d $h:$m:$s"; originally - I fixed it, then changed it back to post it, but I didn't change $min back to $m.

Link to comment
https://forums.phpfreaks.com/topic/206249-hard-to-find-bug/#findComment-1079314
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.