• TruthNerds (google) in reply to thegoryone

    Of course somebody had to play the devil's advocate…

    Look, PHP's syntax is derived from C, including the ternary operator. In C, this operator is right-associative, so a ? b : c ? d : e is the same as a ? b : (c ? d : e).

    However, in PHP, the operator is left-associative, which leads to the behavior shown. I'm not claiming that there is a big "natural" reason why right associativity is better here than left associativity (though the common use cases suggest it). It's just… they created a new language, copied the operator, but reversed the associativity, and didn't even name a reason for doing so. Like, WHY??? It's like making a replica of a car but swapping the gas and brake pedals… not because it's better, just because you can. Or because you don't give an F. Again, WHY???? Anyway, I rest my case.

  • Carrandas (unregistered)

    Ah yes, in our firm we have to check in items as 'bugfix' or 'user story'. Code cleanup is not a possiblity.

  • Most of You Need To Read (unregistered)

    That would solve the issue. PHP was INTENDED to THROW AS FEW ERRORS AS POSSIBLE. It made -- on PURPOSE -- the choice of making assumptions rather than erroring out. It's primary purpose was web pages, and they CHOSE not to throw errors, but to instead make ASSUMPTIONS when they could be made.

    PHP is very flexible, but the "Oh, this has to be compiled because I can't handle interpreted languages" crowd is looking for checks that just aren't there. Grow a pair, read the language requirements and code productively.

    Otherwise, go back to a compiled language you love.

  • NieDzejkob (unregistered) in reply to Raj

    a if b else c

  • pitje (unregistered)

    whut? this site still exists?

    I remember, in the olden days when daily life was still in black-and-white, visting this site and smiling about the insane code sometimes turned up.

    Too bad to see that time is gone, and a formerly nice and funny site too..... what an utter craphole the internet has turned into....

    [ADVERTISEMENT] BUY OUR STUFF! Because commerce is good! Give me mony, "a site costs money". Now, free widgets with every useless Windows Software!

  • Dr. λ the Creator of Variables, Binder of Variables, Applicator of Terms and β-Converter of Redexes (unregistered)

    I WANT TO USE THE TERNARY OPERATOR IN ITS DEFAULT RIGHT ASSOCIATIVE FORM FOR THE HECK OF IT

Leave a comment on “Tern Back”

Log In or post as a guest

Replying to comment #:

« Return to Article