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 this is not your bug, you can add a comment by following this link.
If this is your bug, but 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

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: Wed Apr 24 08:01:29 2024 UTC