Make WordPress Core

#58167 closed defect (bug) (invalid)

PHP Notice in wp-includes/class-wp-block-supports.php

Reported by: laurencebahiirwa's profile laurencebahiirwa Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.2
Component: General Keywords: php81 close reporter-feedback
Focuses: Cc:

Description

I am using PHP 8.1.9
Default theme TwentyTwentyThree

The first notice could have been already reported:

PHP Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in wp-includes/functions.php on line 2165

However, this is new and comes when a page with a custom block is used.

PHP Warning: foreach() argument must be of type array|object, string given in wp-includes/class-wp-block-supports.php on line 204

In as much as the function get_block_wrapper_attributes has type hinting,
See: https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-block-supports.php#L175

get_block_wrapper_attributes( $extra_attributes = array() ) {

The error still shows up. Would it be redundant to add an if check for this on https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-block-supports.php#L204-L208?

I have tried this locally and the error is no more. I would happy to submit a patch if this is viable.

Change History (3)

#1 @sabernhardt
20 months ago

  • Keywords php81 added

Hi and thanks for the report!

Line 2165 is in the wp_normalize_path() function, so this could relate to #57581.

#2 @hellofromTonya
16 months ago

  • Keywords close reporter-feedback added

Hello @laurencebahiirwa,

Welcome back to Core's Trac!

The function get_block_wrapper_attributes() requires an array, more specifically an array of strings. It's optional and thus set to an empty array() if nothing is passed to it. This means something is passing something other than an array data type.

You mentioned it only happens with a custom block. In that custom block, is it calling get_block_wrapper_attributes()? And if yes, what data type is it passing to it? The check for null should be done in the plugin / theme adding the custom block.

Would it be redundant to add an if check for this on https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-block-supports.php#L204-L208?

As the function requires an array, yes, it would be redundant. That said, there is/will be an architectural discussion to determine if a structured approach needs to happen for input (parameter) validation. But that discussion is across all of Core, rather than in just this function.

I'll mark this ticket as a close candidate with the assumption that a custom block is incorrectly calling get_block_wrapper_attributes() with something other than an array.

#3 @hellofromTonya
11 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I'll mark this ticket as a close candidate with the assumption that a custom block is incorrectly calling get_block_wrapper_attributes() with something other than an array.

Closing this ticket as there's been no further follow-up in 5 months.

@laurencebahiirwa does the problem still persists today? If yes, next step is to do a backtrace. Doing so can help to identify the code (in a plugin, theme, script, etc.) that is passing something other than an array. If it's not Core code doing it, then disable that plugin or theme and see if the problem goes away. Else, please reopen this ticket and share your findings. Thank you.

Note: See TracTickets for help on using tickets.