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

TypeError null allowed where string required in argument 3 ($subject) of str_replace #6993

Closed
joejoe04 opened this issue Sep 27, 2024 · 1 comment · Fixed by #7251
Closed
Assignees
Labels
priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@joejoe04
Copy link

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version (tested on 3.16.4, but the code is same as latest version)
  • Used the search feature to ensure that the bug hasn’t been reported before ✅

Describe the bug
The customer reports the following error is logged:

PHP Fatal error: Uncaught TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, null given in /www/gjcyclingshop_242/public/wp-content/plugins/wp-rocket/inc/Engine/Optimization/RegexTrait.php:151

To Reproduce
Steps to reproduce the behavior:
I'm not able to reproduce the error with WP_DEBUG enabled. However, we can see here in this part of the code:

protected function restore_html_comments( $html ) {
if ( empty( $this->html_replace ) ) {
return $html;
}

We need to ensure that $html is a non-empty string to prevent errors like this.

Expected behavior
We should run a check to make sure $html is a string and just return if not.

Maybe this line:

if ( empty( $this->html_replace ) ) {

Could become this:
if ( !is_string( $html ) || empty( $this->html_replace ) ) {

Additional context
Ticket: https://secure.helpscout.net/conversation/2710047950/512718/
Website: https://www.gjcyclingshop.be

Acceptance Criteria (for WP Media team use only)
Clear instructions for developers, to be added before the grooming

@piotrbak piotrbak added type: bug Indicates an unexpected problem or unintended behavior priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available needs: grooming labels Sep 27, 2024
@Miraeld Miraeld self-assigned this Jan 27, 2025
@hanna-meda
Copy link
Contributor

For testing:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium Issues which are important, but no one will go out of business. severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants