Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1 deprecated warning strpos() #56169

Closed
nk-o opened this issue Nov 15, 2023 · 0 comments
Closed

PHP 8.1 deprecated warning strpos() #56169

nk-o opened this issue Nov 15, 2023 · 0 comments
Labels
[Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended

Comments

@nk-o
Copy link
Contributor

nk-o commented Nov 15, 2023

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

@nk-o nk-o added the [Type] Bug An existing feature does not function as intended label Nov 15, 2023
@jordesign jordesign added the [Feature] Blocks Overall functionality of blocks label Nov 15, 2023
@nk-o nk-o closed this as completed Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants