php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #74028 new combined operators ?= and ??=
Submitted: 2017-02-01 15:14 UTC Modified: 2017-02-02 18:25 UTC
From: from_php at puggan dot se Assigned:
Status: Suspended Package: *General Issues
PHP Version: Irrelevant OS:
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: from_php at puggan dot se
New email:
PHP Version: OS:

 

 [2017-02-01 15:14 UTC] from_php at puggan dot se
Description:
------------
Could you make 2 new combined operators:

`$a ?= 4` => `$a = $a ?: 4`
AND
`$a ??= 4` => `$a = $a ?? 4`

Test script:
---------------
<?php

function ofstr($a = NULL, $b = NULL)
{
   $a ?= 1;
   $b ?= 100;
   return "$a of $b";
}

print_r(
   array(
      ofstr(2, 5),
      ofstr(60),
      ofstr(FALSE, 5)
   )
);

Expected result:
----------------
Array
(
    [0] => 2 of 5
    [1] => 60 of 100
    [2] => 1 of 5
)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-02-02 18:25 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-02-02 18:25 UTC] cmb@php.net
There is already an RFC regarding ??=[1] which has been accepted.
It is supposed to be implemented for PHP 7.2. Introducing ?= would
also require an RFC, so feel free to start the RFC process[2}. I'm
suspending this ticket for the time being.

[1] <https://wiki.php.net/rfc/null_coalesce_equal_operator>
[2] <https://wiki.php.net/rfc/howto>
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC