Brian's Bug of the Day

Jan 30, 2008 17:40



1 function rmtmpdir($path){
2 $dir = opendir($path);
3 while (FALSE != ($file = readdir($dir))) {
4 if($file!="." && $file!="..")
5 unlink($file);
6 }
7 closedir($dir);
8 chdir('..');
9 rmdir((string)$path);
10}

The language is php. The bug emerged when I had a file named '0' in the directory. The fix is a 1 character change. Any

Leave a comment

Comments 6

zoal January 30 2008, 22:48:05 UTC
!==

Reply

gameboy9 January 31 2008, 13:35:19 UTC
I'm still learning PHP a bit...

Is this the correct answer because FALSE is another term for '0', therefore FALSE != '0' terminates the while statement?

Reply

zoal January 31 2008, 14:33:28 UTC
FALSE isn't another term for '0' (as in Perl), but string value '0' is considered FALSE in this example, because operator "!=" is not type sensitive. And "!==" is type sensitive.

Reply

gameboy9 January 31 2008, 15:54:33 UTC
Ah... I thought it had something to do with that.

Thanks for the education. :)

Reply


vees January 31 2008, 00:07:31 UTC
My affinity for strongly-typed exception capable languages grows every day.

Reply


Leave a comment

Up