Make WordPress Core


Ignore:
Timestamp:
03/30/2026 05:31:56 AM (2 months ago)
Author:
westonruter
Message:

Code Quality: Replace void with proper return types in union PHPDoc annotations.

In PHP's type system, void means a function does not return a value and cannot be part of a union type. Many functions in core were documented as returning e.g. string|void while actually returning null implicitly via bare return; statements. This replaces void with null in union return types, adds explicit return null; statements, and updates @return annotations across 22 files in wp-includes.

Additionally:

  • Adds @return never for WP_Recovery_Mode::redirect_protected().
  • Fixes WP_Theme_JSON::set_spacing_sizes() to use @return void instead of @return null|void.
  • Removes void from return types where the function always returns a value or dies: remove_theme_support(), WP_Recovery_Mode::handle_error().
  • Fixes wp_die() return type from never|void to void with clarified description.
  • Initializes $primary variable in get_active_blog_for_user() to prevent a possible undefined variable notice.

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

Follow-up to r62177, r61766, r61719.

Props apermo, xateman, westonruter, parthvataliya, nimeshatxecurify.
See #64704.

File:
1 edited

Legend:

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

    r61136 r62178  
    3838 *                              figure if redirect is needed.
    3939 * @param bool   $do_redirect   Optional. Redirect to the new URL.
    40  * @return string|void The string of the URL, if redirect needed.
     40 * @return string|null The string of the URL, if redirect needed. Never returns if a redirect occurs, depending on $do_redirect.
    4141 */
    4242function redirect_canonical( $requested_url = null, $do_redirect = true ) {
     
    4444
    4545    if ( isset( $_SERVER['REQUEST_METHOD'] ) && ! in_array( strtoupper( $_SERVER['REQUEST_METHOD'] ), array( 'GET', 'HEAD' ), true ) ) {
    46         return;
     46        return null;
    4747    }
    4848
     
    6363        || ( $is_IIS && ! iis7_supports_permalinks() )
    6464    ) {
    65         return;
     65        return null;
    6666    }
    6767
     
    7575    $original = parse_url( $requested_url );
    7676    if ( false === $original ) {
    77         return;
     77        return null;
    7878    }
    7979
     
    772772
    773773    if ( ! $redirect_url || $redirect_url === $requested_url ) {
    774         return;
     774        return null;
    775775    }
    776776
     
    831831    // Yes, again -- in case the filter aborted the request.
    832832    if ( ! $redirect_url || strip_fragment_from_url( $redirect_url ) === strip_fragment_from_url( $requested_url ) ) {
    833         return;
     833        return null;
    834834    }
    835835
     
    842842            // Debug.
    843843            // die("1: $redirect_url<br />2: " . redirect_canonical( $redirect_url, false ) );
    844             return;
     844            return null;
    845845        }
    846846    } else {
Note: See TracChangeset for help on using the changeset viewer.