Jump to content

Hard to find bug


tibberous

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.