- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
Ah yes, in our firm we have to check in items as 'bugfix' or 'user story'. Code cleanup is not a possiblity.
Admin
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.
Admin
a if b else c
Admin
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!
Admin
I WANT TO USE THE TERNARY OPERATOR IN ITS DEFAULT RIGHT ASSOCIATIVE FORM FOR THE HECK OF IT
Admin
Yes you do because "working" isn't unambiguous. Something e.g. may work but be uselessly slow.