Skip to content

PHP 8.1 deprecated warning strpos() #56169

@nk-o

Description

@nk-o

Description

In some custom blocks, where we use useInnerBlocksProps with layout support and place any tag without className in save function before tag with inner blocks, we get this warning:

PHP Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /wp-includes/block-supports/layout.php on line 837

Step-by-step reproduction instructions

  1. Create a block with layout supports and with InnerBlocks
  2. Add the similar output for Save function:
function BlockSave() {
  const blockProps = useBlockProps.save();
  const innerBlocksProps = useInnerBlocksProps.save({ className: 'test-inner-blocks' });

  return (
    <div {...blockProps}>
      <div>Test</div>
      <div {...innerBlocksProps} />
    </div>
  );
}
  1. Just place the block on the page, save and check the frontend output. Everything will be rendered correctly, but we will also see the deprecation notice
  2. The reason is simple. This code part is trying to check the 'class' attribute of the block, which doesn't contains a class:
    if ( false !== strpos( $processor->get_attribute( 'class' ), $inner_block_wrapper_classes ) ) {

Screenshots, screen recording, code snippet

Related topic, created by the user of Ghost Kit plugin - https://wordpress.org/support/topic/php-warning-under-php-8-1/

Environment info

  • PHP 8.2.8
  • WordPress 6.4
  • Gutenberg 17.0.2
  • theme is 2024

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] BlocksOverall functionality of blocks[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions