Unlink if you can unlink



  • In a russian forum I found this PHP code:

    if (unlink("../news_photos/smalls/".$filename_old== TRUE) {
         unlink("../news_photos/smalls/".$filename_old);
     }
    So, if you check PHP documentations, unlink returns true after deleting the file, so the second line will try to remove non-existing file and will display a warning message, and the first line will also display warning message if the file does not exist.


  • Copy/Paste, Copy/Paste, Copy/Paste... :D



    And of course, always compare with true and never with 0 (zero).



    After all, who the hk ever reads the f***g manuals?




  • Maybe he or she was trying to do it like this:

    if (unlink("../news_photos/smalls/".$filename_old== TRUE BUT DON'T UNLINK IT YET, STUPID) {
         unlink("../news_photos/smalls/".$filename_old) NOW!!!;
     }

    He or she missed the "Do What I Mean, Not What I Say" operators.

    Oh, they haven't been invented yet. :P

Log in to reply