Make WordPress Core


Ignore:
Timestamp:
09/06/2026 06:38:39 PM (14 hours ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use the null coalescing assignment operator for default value assignments.

Replaces verbose "assign a default only if not already set" patterns with the null coalescing assignment operator (??=):

// Before
$args['title'] = $args['title'] ?? '';

// After
$args['title'] ??= '';

Both forms are functionally identical; ??= is shorter and clearer.

Why this is safe

  • ??= requires PHP 7.4, which is already the minimum.
  • The operator is already used elsewhere in core (e.g. wp-includes/l10n.php, wp-includes/view-config.php), so this only makes existing usage consistent.
  • No behavior change.

Follow-up to r63443, r63501.

Props Soean, mukesh27.
See #65823.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/abilities-api/class-wp-ability.php

    r63391 r63509  
    370370                 * default, then the built-in default applies.
    371371                 */
    372                 $args['meta']['show_in_rest'] = $args['meta']['show_in_rest'] ?? $args['meta']['public'] ?? self::DEFAULT_SHOW_IN_REST;
    373                 $args['meta']['public']       = $args['meta']['public'] ?? self::DEFAULT_PUBLIC;
     372                $args['meta']['show_in_rest'] ??= $args['meta']['public'] ?? self::DEFAULT_SHOW_IN_REST;
     373                $args['meta']['public']       ??= self::DEFAULT_PUBLIC;
    374374
    375375                return $args;
Note: See TracChangeset for help on using the changeset viewer.