# [VOTE] Deprecate left-associative ternary

- Thread: https://externals.io/message/105345
- Original archive: https://news-web.php.net/php.internals/105345
- Started by Nikita Popov on 2019-04-23T08:43:01+00:00
- Messages: 5
- RFC: Deprecate left-associative ternary operator (Implemented (PHP 7.4)) — https://externals.io/rfc/ternary_associativity.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #105345 — Nikita Popov — 2019-04-23T08:43:01+00:00

URL: https://externals.io/message/105345#105345

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

---

## #105389 — Nikita Popov — 2019-04-24T16:27:27+00:00

URL: https://externals.io/message/105345#105389

> 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

---

## #105390 — Paul Jones — 2019-04-24T16:30:31+00:00

URL: https://externals.io/message/105345#105390

Hi all,


> 
> 
> 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

---

## #105403 — Nikita Popov — 2019-04-24T18:11:14+00:00

URL: https://externals.io/message/105345#105403

> Hi all,
>
>
> > […]
>
> I *love* research like this. Really nicely done. Can you share how you
> accomplished it?
>

Sure, here are the scripts I used:
https://gist.github.com/nikic/a2bfa3e2f604f66115c3e4b8963a6c72

This downloads zipballs for the top composer packages, extracts them, and
uses PHP-Parser to check for uses of ternaries affected by this RFC.

Nikita

---

## #105605 — Nikita Popov — 2019-05-07T09:36:37+00:00

URL: https://externals.io/message/105345#105605

> 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
