[VOTE] Deprecate left-associative ternary

php.internals

Nikita Popov

7 years ago
Hi internals, I've opened voting on the RFC to deprecate & remove left associative ternary without explicit parentheses. The vote ends 2019-05-07: https://wiki.php.net/rfc/ternary_associativity The RFC stays as originally proposed: The associativity of the ternary will *not* be changed to right-associative in PHP 8, only the left-associative use without disambiguating parentheses becomes an error. Regards, Nikita

Nikita Popov

7 years ago
On Tue, Apr 23, 2019 at 10:43 AM Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals, > > I've opened voting on the RFC to deprecate & remove left associative > ternary without explicit parentheses. The vote ends 2019-05-07: > > https://wiki.php.net/rfc/ternary_associativity > > The RFC stays as originally proposed: The associativity of the ternary > will *not* be changed to right-associative in PHP 8, only the > left-associative use without disambiguating parentheses becomes an error. > > Regards, > Nikita >
To better judge the BC impact here, I've analyzed the top 1000 composer packages for this pattern. The results are here: https://gist.github.com/nikic/b6214f87b0e4a7c6fe26919ac849194f The tl;dr is that nested ternaries were used a total of 12 times across all files. 9 of these uses are bugs: A right-associative meaning was intended, but PHP will interpret left-associatively. 3 uses of the form $a ? $b : $c ?: $d are potentially okay, because the difference between the two interpretations is small and it's not obvious to me which one is actually intended. Nikita

Paul M Jones

7 years ago
Hi all,
> On Apr 24, 2019, at 11:27, Nikita Popov <nikita.ppv@gmail.com> wrote: > > To better judge the BC impact here, I've analyzed the top 1000 composer > packages for this pattern. The results are here: > https://gist.github.com/nikic/b6214f87b0e4a7c6fe26919ac849194f
I *love* research like this. Really nicely done. Can you share how you accomplished it?
-- Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php

Nikita Popov

7 years ago
On Tue, Apr 23, 2019 at 10:43 AM Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals, > > I've opened voting on the RFC to deprecate & remove left associative > ternary without explicit parentheses. The vote ends 2019-05-07: > > https://wiki.php.net/rfc/ternary_associativity > > The RFC stays as originally proposed: The associativity of the ternary > will *not* be changed to right-associative in PHP 8, only the > left-associative use without disambiguating parentheses becomes an error. > > Regards, > Nikita >
This RFC has been accepted with 35 votes in favor and 10 against. Nikita