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

From: Date: Sat, 19 Oct 2013 02:46:07 +0000
Subject: Re: Re: Why PHP sucks - farce or is there a bit of truth?
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-322320@lists.php.net to get a copy of this message
*lol* On 13-10-18 09:43 PM, Jonathan Sundquist wrote:
Always develop like the next person to work on the code is an axe murderer who know where you live. On Oct 18, 2013 7:56 PM, "TQ White II" <tq@justkidding.com> wrote:
If you wrote a nested ternary like that I'd fire your ass. As one of the main programming philosophers said, the art of programming is making your intentions clear to the next programmer. ----------------------------------- TQ White II 708-763-0100
On Oct 18, 2013, at 2:02 PM, Jim Giner <jim.giner@albanyhandball.com>
wrote:
On 10/18/2013 10:33 AM, Robert Cummings wrote: 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.
When I write something like this, I expect it to happen from left to
right. Always have, always will. That said I see the 'proper' expectation of this statement:
$foo = $a ? $b : $c ? $d : $e; as: $foo will be the result of "if $a then $b else if $c then $d else $e;" Why php interprets it differently is just not logical to me. Of course
writing something like that with one set of parens solves the riddle as well as making it more readable:
$foo = $a ? $b : ($c ? $d : $e); As for ambiguity - I don't see it. Again the literal syntax of the
ternary if is (IMHO):
"if (cond) then (statement) else (other statment)" In your example:
      $foo = $a ? $b : $c ? $d : $e;
I see it exactly as this: "if $a is true then $b else
    if $c is true then
    $d
    else
    $e;"
Why should php evaluate the last statement before deciding if it even
needs that statement?
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- 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 (#322320) next »