php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79673 "roughly equivalent to" without explaining the difference
Submitted: 2020-06-04 11:21 UTC Modified: -
From: kasperheij at hotmail dot com Assigned:
Status: Open Package: Documentation problem
PHP Version: 7.4.6 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-06-04 11:21 UTC] kasperheij at hotmail dot com
Description:
------------
---
From manual page: https://php.net/migration74.new-features
---

```
<?php
$array['key'] ??= computeDefault();
// is roughly equivalent to
if (!isset($array['key'])) {
    $array['key'] = computeDefault();
}
?>
```

"// is roughly equivalent to" says that there _is_ a difference without specifying this delta.




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-10 18:18 UTC] alexinbeijing at gmail dot com
Interesting question!

I can't find any difference in the actual behavior, although the bytecodes executed by the interpreter are different in either case, so it is possible that there might be some (very small) difference in performance.

See:

https://3v4l.org/Z3dPV/vld#output
https://3v4l.org/2W7W1/vld#output
 [2020-06-17 21:54 UTC] a at b dot c dot de
The "??=" operator isn't mentioned at all in the reference part of the documentation (under neither "comparison operators", where the base '??' is given; nor "assignment operators", which description of "combined operators" hasn't been updated). One of those would be the place to describe its behaviour and how it's different from the more long-winded form.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 30 07:01:23 2020 UTC