Make WordPress Core

Changeset 60809

Timestamp:
09/29/2025 04:28:00 PM (9 days ago)
Author:
swissspidy
Message:

Code Modernization: Fix instances of using null as an array offset.

Addresses a new deprecation in PHP 8.5.

Props swissspidy.
Fixes #63957.

Location:
trunk
Files:
9 edited

Legend:

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

    r60807 r60809  
    149149
    150150    $supported_block_attributes =
    151         $block_bindings_supported_attributes[ $block_type ] ??
    152         array();
     151        isset( $block_type, $block_bindings_supported_attributes[ $block_type ] ) ?
     152            $block_bindings_supported_attributes[ $block_type ] :
     153            array();
    153154
    154155    /**
  • trunk/src/wp-includes/blocks.php

    r60708 r60809  
    939939function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
    940940    $anchor_block_type  = $parsed_anchor_block['blockName'];
    941     $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
     941    $hooked_block_types = isset( $anchor_block_type, $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
    942942        ? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
    943943        : array();
     
    10301030function set_ignored_hooked_blocks_metadata( &$parsed_anchor_block, $relative_position, $hooked_blocks, $context ) {
    10311031    $anchor_block_type  = $parsed_anchor_block['blockName'];
    1032     $hooked_block_types = isset( $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
     1032    $hooked_block_types = isset( $anchor_block_type, $hooked_blocks[ $anchor_block_type ][ $relative_position ] )
    10331033        ? $hooked_blocks[ $anchor_block_type ][ $relative_position ]
    10341034        : array();
  • trunk/src/wp-includes/class-wp-block-type-registry.php

    r60804 r60809  
    135135     * @since 5.0.0
    136136     *
    137      * @param string $name Block type name including namespace.
     137     * @param string|null $name Block type name including namespace.
    138138     * @return WP_Block_Type|null The registered block type, or null if it is not registered.
    139139     */
     
    162162     * @since 5.0.0
    163163     *
    164      * @param string $name Block type name including namespace.
     164     * @param string|null $name Block type name including namespace.
    165165     * @return bool True if the block type is registered, false otherwise.
    166166     */
    167167    public function is_registered( $name ) {
    168         return isset( $this->registered_block_types[ $name ] );
     168        return isset( $name, $this->registered_block_types[ $name ] );
    169169    }
    170170
  • trunk/src/wp-includes/class-wp-hook.php

    r56609 r60809  
    8181     */
    8282    public function add_filter( $hook_name, $callback, $priority, $accepted_args ) {
     83        if ( null === $priority ) {
     84            $priority = 0;
     85        }
     86
    8387        $idx = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
    8488
     
    188192     */
    189193    public function remove_filter( $hook_name, $callback, $priority ) {
     194        if ( null === $priority ) {
     195            $priority = 0;
     196        }
     197
    190198        $function_key = _wp_filter_build_unique_id( $hook_name, $callback, $priority );
    191199
    192         $exists = isset( $this->callbacks[ $priority ][ $function_key ] );
     200        $exists = isset( $function_key, $this->callbacks[ $priority ][ $function_key ] );
    193201
    194202        if ( $exists ) {
  • trunk/src/wp-includes/class-wp-theme-json.php

    r60409 r60809  
    28902890        $element_pseudo_allowed = array();
    28912891
    2892         if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
     2892        if ( isset( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
    28932893            $element_pseudo_allowed = static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ];
    28942894        }
  • trunk/src/wp-includes/functions.php

    r60776 r60809  
    51025102             * than `array_key_exists()`.
    51035103             */
    5104             if ( isset( $input_array[ $path_element ] ) ) {
     5104            if ( isset( $path_element, $input_array[ $path_element ] ) ) {
    51055105                $input_array = $input_array[ $path_element ];
    51065106                continue;
     
    51115111             * which also checks for `null` values.
    51125112             */
    5113             if ( array_key_exists( $path_element, $input_array ) ) {
     5113            if ( isset( $path_element ) && array_key_exists( $path_element, $input_array ) ) {
    51145114                $input_array = $input_array[ $path_element ];
    51155115                continue;
  • trunk/tests/phpunit/data/html-api/token-counting-html-processor.php

    r59364 r60809  
    2424        }
    2525
     26        if ( null === $token_name ) {
     27            $token_name = '';
     28        }
     29
    2630        if ( ! isset( $this->token_seen_count[ $token_name ] ) ) {
    2731            $this->token_seen_count[ $token_name ] = 1;
  • trunk/tests/phpunit/tests/functions/wpArrayGet.php

    r56971 r60809  
    239239            true
    240240        );
    241 
    242         $this->assertSame(
    243             _wp_array_get(
    244                 array(
    245                     'key' => array(
    246                         null => 4,
    247                     ),
    248                 ),
    249                 array( 'key', null ),
    250                 true
    251             ),
    252             4
    253         );
    254241    }
    255242
  • trunk/tests/phpunit/tests/post/isPostStatusViewable.php

    r57987 r60809  
    141141            array( true, false ),
    142142            array( 20, false ),
    143             array( null, false ),
    144143            array( '', false ),
    145144        );
Note: See TracChangeset for help on using the changeset viewer.