Make WordPress Core


Ignore:
Timestamp:
09/06/2026 06:38:39 PM (9 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-admin/edit-form-advanced.php

    r62696 r63509  
    6868 * @var int
    6969 */
    70 $post_ID = isset( $post_ID ) ? (int) $post_ID : 0;
    71 $user_ID = isset( $user_ID ) ? (int) $user_ID : 0;
    72 $action  = $action ?? '';
     70$post_ID  = isset( $post_ID ) ? (int) $post_ID : 0;
     71$user_ID  = isset( $user_ID ) ? (int) $user_ID : 0;
     72$action ??= '';
    7373
    7474if ( (int) get_option( 'page_for_posts' ) === $post->ID && empty( $post->post_content ) ) {
Note: See TracChangeset for help on using the changeset viewer.