|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72047 Support a "conditional assignment" operator like ruby's `||=`
Submitted: 2016-04-18 08:38 UTC Modified: 2016-04-18 10:05 UTC
From: oded at geek dot co dot il Assigned: requinix (profile)
Status: Closed Package: Variables related
PHP Version: 7.0.5 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: oded at geek dot co dot il
New email:
PHP Version: OS:


 [2016-04-18 08:38 UTC] oded at geek dot co dot il
From manual page:

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'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-18 09:27 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: requinix
 [2016-04-18 09:27 UTC]
Already been accepted, though the PR for it is still pending.
 [2016-04-18 10:05 UTC] oded at geek dot co dot il
I'm happy to see that I'm not breaking any new ground here :-) 

waiting with anticipation.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jul 31 18:01:24 2021 UTC