php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #72675 Null coalesce operator example has if/else wrong way round
Submitted: 2016-07-26 10:04 UTC Modified: 2016-07-26 10:25 UTC
From: jonny at jonnybarnes dot uk Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 7.0.9 OS:
Private report: No CVE-ID: None
 [2016-07-26 10:04 UTC] jonny at jonnybarnes dot uk
Description:
------------
The Null coalesce operator has an incorrect example. See https://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

    <?php
    // Example usage for: Null Coalesce Operator
    $action = $_POST['action'] ?? 'default';
    
    // The above is identical to this if/else statement
    if (isset($_POST['action'])) {
        $action = 'default';
    } else {
        $action = $_POST['action'];
    }
    ?>

Should actually be:

    <?php
    // Example usage for: Null Coalesce Operator
    $action = $_POST['action'] ?? 'default';
    
    // The above is identical to this if/else statement
    if (isset($_POST['action'])) {
        $action = $_POST['action'];
    } else {
        $action = 'default';
    }
    ?>

See this 3v4l for confirmation: https://3v4l.org/H3V7m


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-26 10:24 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339720
Log: Fix #72675: Null coalesce operator example has if/else wrong way round
 [2016-07-26 10:25 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-07-26 10:25 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2355dfd77be34099f8b2a1f8af1d2e0c74ab67bb
Log: Fix #72675: Null coalesce operator example has if/else wrong way round
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 09:00:02 2026 UTC