Req #72047 [Csd]: Support a "conditional assignment" operator like ruby's `||=`
| From: | oded at geek dot co dot il | Date: | Mon, 18 Apr 2016 10:05:20 +0000 |
| Subject: | Req #72047 [Csd]: Support a "conditional assignment" operator like ruby's `||=` | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200625@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=72047&edit=1
ID: 72047
User updated by: oded at geek dot co dot il
Reported by: oded at geek dot co dot il
Summary: Support a "conditional assignment" operator like
ruby's
||=
Status: Closed
Type: Feature/Change Request
Package: Variables related
Operating System: Linux
PHP Version: 7.0.5
Assigned To: requinix
Block user comment: N
Private report: N
New Comment:
I'm happy to see that I'm not breaking any new ground here :-)
waiting with anticipation.
Previous Comments:
------------------------------------------------------------------------
[2016-04-18 09:27:02] requinix@php.net
Already been accepted, though the PR for it is still pending. https://wiki.php.net/rfc/null_coalesce_equal_operator
------------------------------------------------------------------------
[2016-04-18 08:38:40] oded at geek dot co dot il
Description:
------------
---
From manual page: http://www.php.net/language.operators.assignment
---
I often find myself setting default values to variables using syntax of the form:
$a = $a ?? "default";
The same code in Ruby would be written as
a ||= "default"
Which is more concise and reduces boilerplate. It would be great if PHP could support such shorthand
syntax. For example, how about a "null coalescing" assignment operator:
$a ??= 'default'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72047&edit=1