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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
17 - 7 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 15:01:28 2024 UTC