Re: [RFC] Fix the Tenary Operator -- Please!? Please?
| From: | Rowan Collins | Date: | Fri, 27 Mar 2015 08:57:12 +0000 |
| Subject: | Re: [RFC] Fix the Tenary Operator -- Please!? Please? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85498@lists.php.net to get a copy of this message | ||
On 26 March 2015 22:40:56 GMT, Alain Williams <addw@phcomp.co.uk> wrote:
>On Thu, Mar 26, 2015 at 10:31:00PM +0000, Rowan Collins wrote:
>
>> What I've always been annoyed by is the *precedence* of the operator
>- having to add brackets to mix it with string concatenation, etc -
>which it turns out to is the same in all sorts of languages.
>
>It is the ''all sorts of languages'' that is key here. The point is
>that PHP
>associativity for ?: is different from other languages and it is that
>that
>confuses and leads to bugs. What is right/wrong is not as important as
>all
>others doing it the other way.
This reply is competely out of context to the message you quote. Yes, I know that the
*associativity* of the operator is wrong. My contention is that in practice, few people ever try to
associate multiple instances of the operator, so few bugs result from it not working.
I contrasted this with *precedence*, particularly the precedence of an expression mixing the ternary
operator with string concatenation, which is a much more common thing to do. But here, PHP is doing
the "right" thing, if measured by other languages doing the same.
Personally, I'd be in favour of making the operator non-associative, thus breaking obviously if
people try it. Changing it now would result in people using it in PHP 7, then running the code under
PHP 5 and having obscure bugs to fix.
Regards,
--
Rowan Collins
[IMSoP]