Make WordPress Core


Ignore:
Timestamp:
03/30/2026 05:31:56 AM (7 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/class-wp-admin-bar.php

    r61997 r62178  
    194194         *
    195195         * @param string $id
    196          * @return object|void Node.
     196         * @return object|null Node.
    197197         */
    198198        final public function get_node( $id ) {
    … …  
    201201                        return clone $node;
    202202                }
     203                return null;
    203204        }
    204205
    … …  
    207208         *
    208209         * @param string $id
    209          * @return object|void
     210         * @return object|null
    210211         */
    211212        final protected function _get_node( $id ) {
    212213                if ( $this->bound ) {
    213                         return;
     214                        return null;
    214215                }
    215216
    … …  
    221222                        return $this->nodes[ $id ];
    222223                }
    223         }
    224 
    225         /**
    226          * @since 3.3.0
    227          *
    228          * @return array|void
     224                return null;
     225        }
     226
     227        /**
     228         * @since 3.3.0
     229         *
     230         * @return array|null
    229231         */
    230232        final public function get_nodes() {
    231233                $nodes = $this->_get_nodes();
    232234                if ( ! $nodes ) {
    233                         return;
     235                        return null;
    234236                }
    235237
    … …  
    243245         * @since 3.3.0
    244246         *
    245          * @return array|void
     247         * @return array|null
    246248         */
    247249        final protected function _get_nodes() {
    248250                if ( $this->bound ) {
    249                         return;
     251                        return null;
    250252                }
    251253
    … …  
    308310         * @since 3.3.0
    309311         *
    310          * @return object|void
     312         * @return object|null
    311313         */
    312314        final protected function _bind() {
    313315                if ( $this->bound ) {
    314                         return;
     316                        return null;
    315317                }
    316318
Note: See TracChangeset for help on using the changeset viewer.