Skip navigation.

I am WTF Seven of Nine of "Ternary" Adjunct...

Fugly Code

Thanks to Alex @ TheDailyWTF for forwarding this WTF to me. The WTF is originally from James who found it as a patch for OSCommerce. OSCommerce is one of the most popular and oldest PHP projects. The project started out under a different name but it became popular enough that the project was renamed and remarketed as OSCommerce.

James said:
This patch (attached) for the popular OScommerce shopping cart software adds the functionality to resize images to thumbnail size on demand and cache it for later use. It works - but oh my!
!isset ($image)
           ? DIE ('Es wurde kein Bild angegeben!')
           : !file_exists($image)
                ? DIE ('Die angegebene Datei konnte nicht auf dem Server gefunden werden!')
                : false;

Oh my indeed! This is not what the ternary operator is ment for. The ternary operator is ment to be a shortcut to using if/else to assign a variable one of two values. It is not ment to be a general short form of if/else. Also using die() to handle exceptions is the lazy programmer's way out, especially in a popular application like OSCommerce.

This is probably a better way to do it. Look ma, less code too!

if (!isset($image))
'Es wurde kein Bild angegeben!');
elseif (!
'Die angegebene Datei konnte nicht auf dem Server gefunden werden!');

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

last time i heard, it was cal

last time i heard, it was called a "ternary" operator.... tertiary.. wtf? (gotcha).
( )

LOL. Oops, a little too much

LOL. Oops, a little too much x-mas crack. Fixed.

I know programmers are supp

I know programmers are supposed to be lazy, but I hate it when people write if/else statements without braces. I don't care if you technically "don't need" them, I've seen to many times where a programmer goes back to add something to part of result of a conditional only to find that it runs every time because they didn't realize there were no braces. Not to mention the clarity that braces add.

Ditto. I really hate progra

Ditto. I really hate programming books that save money by not putting in the braces. Too lazy.

WTFs like this one merely s

WTFs like this one merely show what a weak copy of the original this site here is. Yawn.

Yeah, yeah, go ahead and delete this comment. Yawn yawn.

actually isset($image) o


isset($image) or die("kein Bild"); file_exists($image) or die("File not found");

seems to be more elegant and readable...