Req #72047 [Opn->Csd]: Support a "conditional assignment" operator like ruby's `||=`
| From: | requinix@php.net | Date: | Mon, 18 Apr 2016 09:27:04 +0000 |
| Subject: | Req #72047 [Opn->Csd]: Support a "conditional assignment" operator like ruby's `||=` | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-200623@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
Updated by: requinix@php.net
Reported by: oded at geek dot co dot il
Summary: Support a "conditional assignment" operator like
ruby's
||=
-Status: Open
+Status: Closed
Type: Feature/Change Request
Package: Variables related
Operating System: Linux
PHP Version: 7.0.5
-Assigned To:
+Assigned To: requinix
Block user comment: N
Private report: N
New Comment:
Already been accepted, though the PR for it is still pending. https://wiki.php.net/rfc/null_coalesce_equal_operator
Previous Comments:
------------------------------------------------------------------------
[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