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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 11:01:34 2025 UTC