Skip to content

Commit ee22a18

Browse files
committed
Code Modernization: Fix instances of using null as an array offset.
Addresses a new [https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_using_values_null_as_an_array_offset_and_when_calling_array_key_exists deprecation in PHP 8.5]. Props swissspidy. Fixes #63957. git-svn-id: https://develop.svn.wordpress.org/trunk@60809 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ff6c5fa commit ee22a18

File tree

9 files changed

+24
-25
lines changed

9 files changed

+24
-25
lines changed

src/wp-includes/block-bindings.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,9 @@ function get_block_bindings_supported_attributes( $block_type ) {
148148
);
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
/**
155156
* Filters the supported block attributes for block bindings.

src/wp-includes/blocks.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ function get_hooked_blocks() {
938938
*/
939939
function 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();
944944

@@ -1029,7 +1029,7 @@ function insert_hooked_blocks( &$parsed_anchor_block, $relative_position, $hooke
10291029
*/
10301030
function 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();
10351035

src/wp-includes/class-wp-block-type-registry.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function unregister( $name ) {
134134
*
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
*/
140140
public function get_registered( $name ) {
@@ -161,11 +161,11 @@ public function get_all_registered() {
161161
*
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

171171
public function __wakeup() {

src/wp-includes/class-wp-hook.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ final class WP_Hook implements Iterator, ArrayAccess {
8080
* @param int $accepted_args The number of arguments the function accepts.
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

8589
$priority_existed = isset( $this->callbacks[ $priority ] );
@@ -187,9 +191,13 @@ private function resort_active_iterations( $new_priority = false, $priority_exis
187191
* @return bool Whether the callback existed before it was removed.
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 ) {
195203
unset( $this->callbacks[ $priority ][ $function_key ] );

src/wp-includes/class-wp-theme-json.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2889,7 +2889,7 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) {
28892889

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
}
28952895

src/wp-includes/functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5101,7 +5101,7 @@ function _wp_array_get( $input_array, $path, $default_value = null ) {
51015101
* We check with `isset()` first, as it is a lot faster
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;
51075107
}
@@ -5110,7 +5110,7 @@ function _wp_array_get( $input_array, $path, $default_value = null ) {
51105110
* If `isset()` returns false, we check with `array_key_exists()`,
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;
51165116
}

tests/phpunit/data/html-api/token-counting-html-processor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public function next_token(): bool {
2323
$token_name = $this->get_token_name();
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;
2832
} else {

tests/phpunit/tests/functions/wpArrayGet.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,6 @@ public function test_wp_array_get_null() {
238238
),
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

256243
/**

tests/phpunit/tests/post/isPostStatusViewable.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ public function data_built_unregistered_in_status_types() {
140140
array( false, false ),
141141
array( true, false ),
142142
array( 20, false ),
143-
array( null, false ),
144143
array( '', false ),
145144
);
146145
}

0 commit comments

Comments
 (0)