WebEdition PHP CMS



  • I just found this atrocity in the webEdition code (it's a crap PHP CMS http://www.webedition.de/en/):



    [img]http://img4.imageshack.us/img4/9329/wearraykeyexistsabomina.png[/img]



    btw: this forum sucks, requiring html <br> to create linebreaks? c'mon...



  • Sheesh, how retarded do you have to be to write this...



  • Oh come on... it's not that bad.

    Sure, you could use <font face="courier new,courier">isset</font>(), but at least this is functional, isn't it?

    Edit: oh, and <font face="courier new,courier">array_key_exists()</font>.  


  • Winner of the 2016 Presidential Election

    I frequently see a former coworker of mine write: someExpression ? true : false

    As well as, someString.ToString() and (LINQ) from x in y select x. He likes the verbose no-ops.



  • Depending on which bastard-offspring-of-C language you're coding in, someExpression ? true : false can be a perfectly reasonable way to cast something into a boolean.  (Using it in a strongly typed B&D language like Java would be a WTF, of course.)  Sure, you could shorten it to !!someExpression, but honestly, you had to look at that twice to figure out what it did, didn't you?  Of course, in most languages the cleanest way to write that would be something like (boolean) someExpression.


  • Discourse touched me in a no-no place

    @vyznev said:

    Sure, you could shorten it to !!someExpression, but honestly, you had to look at that twice to figure out what it did, didn't you?
    Um no - it's an idiom that, while perhaps not common, isn't unknown.



  • @vyznev said:

    Depending on which bastard-offspring-of-C language you're coding in, someExpression ? true : false can be a perfectly reasonable way to cast something into a boolean.  (Using it in a strongly typed B&D language like Java would be a WTF, of course.)  Sure, you could shorten it to !!someExpression, but honestly, you had to look at that twice to figure out what it did, didn't you?  Of course, in most languages the cleanest way to write that would be something like (boolean) someExpression.

    This is PHP so the ternary is redundant, although I admit I sometimes forget the shortcut of storing the result of the expression in a variable and use the ternary anyway.



  •  I can't fully justify this, but one way you can wind up with code like this is if at one time there was code to create a log entry in the 'else'. Once the code was tested, the log entry was removed, but the person removing it didn't want to make any more changes than needed, and it's possible someone might want to put the log entry back.

     This is easier to justify if there had been a commented-out logging command there, of course.



  • @morbiuswilters said:

    This is PHP so the ternary is redundant, although I admit I sometimes forget the shortcut of storing the result of the expression in a variable and use the ternary anyway.
    I'll never get over the left associativity of PHP's ternary operator.

    <font face="courier new,courier">$how_many = $qty < 2 ? 'too few' : $qty > 2 ? 'too much' : 'just right';</font>

    is interpreted as

    <font face="courier new,courier">$how_many = ($qty < 2 ? 'too few' : $qty > 2) ? 'too much' : 'just right';</font>

    at and makes <font face="courier new,courier">$how_many</font> become an unexpected <font face="courier new,courier">'too much'</font> when <font face="courier new,courier">$qty == 1</font>.



  • @Zecc said:

    @morbiuswilters said:

    This is PHP so the ternary is redundant, although I admit I sometimes forget the shortcut of storing the result of the expression in a variable and use the ternary anyway.
    I'll never get over the left associativity of PHP's ternary operator.

    <font face="courier new,courier">$how_many = $qty < 2 ? 'too few' : $qty > 2 ? 'too much' : 'just right';</font>

    is interpreted as

    <font face="courier new,courier">$how_many = ($qty < 2 ? 'too few' : $qty > 2) ? 'too much' : 'just right';</font>

    at and makes <font face="courier new,courier">$how_many</font> become an unexpected <font face="courier new,courier">'too much'</font> when <font face="courier new,courier">$qty == 1</font>.

    Nested ternaries are always a WTF, IMO.



  • if (boolean) {
    return true;
    }
    else {
    return false;
    }

    ... is how I'd code if I were paid by the line.



  • @gherkin said:

    ... is how I'd code if I were paid by the line.
    Pfft! You and your sticking to K&R.
    if 
    (
    boolean
    )
    {
    return
    true;
    }
    else
    {
    return
    false;
    }



  • Re: Line breaks

    I might be kinda slow to find out the <br> requirement, but thank you for telling me how to do it!


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.