Make WordPress Core


Ignore:
Timestamp:
12/22/2025 11:12:59 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Replace some isset() ternary checks with null coalescing.

Since PHP 7.0 introduced the null coalescing operator, and WordPress now requires at least PHP 7.2.24, isset( $var ) ? $var : null ternary checks can be safely replaced with the more concise $var ?? null syntax.

As some new code using the null coalescing operator has already been introduced into core in recent releases, this commit continues with the code modernization by implementing incremental changes for easier review.

Props seanwei, getsyash, krupalpanchal, wildworks, jorbin, SergeyBiryukov.
Fixes #63430. See #58874.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-query.php

    r61387 r61403  
    30203020                        $clauses = (array) apply_filters_ref_array( 'posts_clauses', array( compact( $pieces ), &$this ) );
    30213021
    3022                         $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    3023                         $groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
    3024                         $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
    3025                         $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    3026                         $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
    3027                         $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    3028                         $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
     3022                        $where    = $clauses['where'] ?? '';
     3023                        $groupby  = $clauses['groupby'] ?? '';
     3024                        $join     = $clauses['join'] ?? '';
     3025                        $orderby  = $clauses['orderby'] ?? '';
     3026                        $distinct = $clauses['distinct'] ?? '';
     3027                        $fields   = $clauses['fields'] ?? '';
     3028                        $limits   = $clauses['limits'] ?? '';
    30293029                }
    30303030
     
    31543154                        $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $pieces ), &$this ) );
    31553155
    3156                         $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    3157                         $groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
    3158                         $join     = isset( $clauses['join'] ) ? $clauses['join'] : '';
    3159                         $orderby  = isset( $clauses['orderby'] ) ? $clauses['orderby'] : '';
    3160                         $distinct = isset( $clauses['distinct'] ) ? $clauses['distinct'] : '';
    3161                         $fields   = isset( $clauses['fields'] ) ? $clauses['fields'] : '';
    3162                         $limits   = isset( $clauses['limits'] ) ? $clauses['limits'] : '';
     3156                        $where    = $clauses['where'] ?? '';
     3157                        $groupby  = $clauses['groupby'] ?? '';
     3158                        $join     = $clauses['join'] ?? '';
     3159                        $orderby  = $clauses['orderby'] ?? '';
     3160                        $distinct = $clauses['distinct'] ?? '';
     3161                        $fields   = $clauses['fields'] ?? '';
     3162                        $limits   = $clauses['limits'] ?? '';
    31633163                }
    31643164
Note: See TracChangeset for help on using the changeset viewer.