Make WordPress Core

Opened 5 months ago

Last modified 7 weeks ago

#58167 new defect (bug)

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

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


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,

get_block_wrapper_attributes( $extra_attributes = array() ) {

The error still shows up. Would it be redundant to add an if check for this on

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

Change History (2)

#1 @sabernhardt
5 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
7 weeks 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

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.

Note: See TracTickets for help on using tickets.