# RFC: Short Ternary Assignment Operator

- Status: Inactive
- Authors: Sara Golemon pollita@php.net (Heavily cribbed from Midori Kocak mtkocak@gmail.com)
- Date: 2016-03-10
- Version: 0.1.0
- Original: https://wiki.php.net/rfc/short_ternary_equal_operator
- Page: https://externals.io/rfc/short_ternary_equal_operator
- 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

## Votes

### Approve Short Ternary Assignment Operator RFC and merge oatch into master? (closed)

Yes: 0 · No: 0

## Discussions on the mailing list

- [\[RFC\] \[Vote\] Short Ternary Assignment Operator](https://externals.io/message/91901.md) — started on 2016-03-24, 9 messages
- [Supports to ?:= assignment operator](https://externals.io/message/112222.md) — started on 2020-11-11, 2 messages

---

## Introduction

Most binary expressions in PHP (e.g. &#96;$x = $y op $z;&#96;) have a shorthand form for self assignment (where the lefthand of the binary op is the same as the lefthand of the assignment), in this example: &#96;$x = $x op $y;&#96; is the same as &#96;$x op= $y;&#96;. While it's true for most binary operations, it is not true for the null coalesce operator (the subject of [http://wiki.php.net/rfc/null\_coalesce\_equal\_operator](https://externals.io/rfc/null_coalesce_equal_operator) ) or the short ternary operator: &#96;?:&#96;.

## Proposal

Add an assignment operatory for short ternary expressions such that the following two lines of code are equivalent:

```php
$x = $x ?: $y;
$x ?:= $y;
```

Thus, the value of right-hand parameter is assigned by value to the left-hand variable if the left-hand variable is currently falsy.

## Proposed PHP Version(s)

This proposed for the next PHP 7.x.

## Patches and Tests

<https://github.com/php/php-src/compare/master...sgolemon:short-ternary.coalesce>

## Vote

As this is a language change, a 2/3 majority is required. A straight Yes/No vote is being held.

**Vote: Approve Short Ternary Assignment Operator RFC and merge oatch into master?** — Yes: 0 · No: 0 (closed)

On 2016-03-24 vote was closed a few hours after opening (at 9:3 in favor) due to issues with the proposed implementation. It will be reopened at a later time (with a fresh vote).

## References

This is essentially the same proposal as [https://wiki.php.net/rfc/null\_coalesce\_equal\_operator](https://externals.io/rfc/null_coalesce_equal_operator) with a focus on the short ternary operator, rather than the null coalesce operator.
