|  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: 2021-02-01 17:21 UTC
From: kasperheij at hotmail dot com Assigned:
Status: Verified Package: Documentation problem
PHP Version: 7.4.6 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:
Solve the problem:
48 - 15 = ?
Subscribe to this entry?

 [2020-06-04 11:21 UTC] kasperheij at hotmail dot com
From manual page:

$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.


Add a Patch

Pull Requests

Add a Pull Request


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.

 [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.
 [2021-02-01 17:21 UTC]
The problem is that the original RFC[1] was underspecified[2], and
the final implementation[3] turned out to be much harder than

Anyhow, I think the given code snippets are equivalent, even if
`$array instanceof ArrayAccess`.  However, if the literal 'key'
would be replaced with a function call, the function would only be
called once with the ??= operator, but may be called twice with
the "rough equivalent"[4].

> The "??=" operator isn't mentioned at all in the reference part
> of the documentation […]

This has been fixed in the meantime[5], but the given equivalence
is wrong.

[1] <>
[2] <>
[3] <>
[4] <>
[5] <>
 [2021-02-01 17:21 UTC]
-Status: Open +Status: Verified
 [2023-01-05 08:11 UTC] alisaudfxbpn53 at gmail dot com
That was so amazing. 

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 05:01:30 2024 UTC