Make WordPress Core


Ignore:
Timestamp:
07/29/2026 12:07:38 PM (8 weeks ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Use the null coalescing operator for isset() return checks.

This commit replaces a handful of verbose isset() guard patterns with the null coalescing operator (??):

<?php
// Before
if ( isset( $x ) ) {
    return $x;
} else {
    return $default;
}
    
// After
return $x ?? $default;

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

Developed in https://github.com/WordPress/wordpress-develop/pull/12602.

Follow-up to [61463], [61470], [62870].

Props Soean, westonruter.
See #64897.

File:
1 edited

Legend:

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

    r62293 r62895  
    856856        );
    857857
    858         if ( isset( $translation[ $constant ] ) ) {
    859                 return $translation[ $constant ];
    860         } else {
    861                 return false;
    862         }
    863 }
     858        return $translation[ $constant ] ?? false;
     859}
Note: See TracChangeset for help on using the changeset viewer.