Re: Re: Why PHP sucks - farce or is there a bit of truth?

From: Date: Fri, 18 Oct 2013 14:33:27 +0000
Subject: Re: Re: Why PHP sucks - farce or is there a bit of truth?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-322314@lists.php.net to get a copy of this message
On 13-10-18 10:13 AM, Jim Giner wrote:
On 10/17/2013 8:50 PM, Tim-Hinnerk Heuer wrote: Having endured this entire thread (from T-to-B) I have to add my $.02. I recently experienced the rather unexpected outcome of a ternary within a ternary. Rather than consider the order of evaluation being L-to-R or R-to-L, I merely diagnosed it as a simple bug in PHP - which BTW I love, despite it's less than consistent syntax. Reading all the talk of order of evaluation, I have to say in my 40+ years of programming in a variety of languages, I can't recall ever having to consider the topic. When I wrote code I always expected and relied upon the order being the way I wrote it. And - I usually added parentheses to help clarify in my mind what I was doing with the statement as I wrote it, although sometimes I knew they were necessary to achieve the analysis I had in mind. So - as expected, the ternary operator does work from L-to-R except when joined with a second (or third?) ternary operator. Why that is I can't figure out other than to assume it's an un-resolved bug, that occurs so seldom it's probably never been issued. Oh, well.....
Hi Jim, I'm not sure it's a bug. There are two considerations... should the first use of the ternary operator feed the first operand of the second, or should the second use of the ternary operator feed the 3rd operand of the first use. Visually... which is more correct: <?php
    $foo = ($a ? $b : $c) ? $d : $e;  // PHP does this one.
    $foo = $a ? $b : ($c ? $d : $e);
?> They both seem perfectly reasonable and so I would say it's my job to clarify if I don't want to leave it the the vagaries of the developer's subjective opinion :) To me this isn't a flaw in PHP, but an oversight by the programmer (because they don't see the ambiguity) or they have an incorrect assumption that one way is the right way. Either way... do you think the following makes for readable code? <?php
    $foo = $a ? $b : $c ? $d : $e;
?> Cheers, Rob. -- E-Mail Disclaimer: Information contained in this message and any attached documents is considered confidential and legally protected. This message is intended solely for the addressee(s). Disclosure, copying, and distribution are prohibited unless authorized.

« previous php.general (#322314) next »