Make WordPress Core

Opened 17 months ago

Closed 12 months ago

Last modified 12 months ago

#57867 closed enhancement (invalid)

Fix PHP warning when passing NULL to rtrim().

Reported by: tools400's profile tools400 Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.2
Component: Formatting Keywords: has-patch reporter-feedback php81
Focuses: Cc:


I have created a pull request for fixing the following PHP warning in src/wp-includes/formatting.php:

[04-Mar-2023 10:45:00 UTC] PHP Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /homepages/36/d24807059/htdocs/clickandbuilds/BergsportFamilieRaddatz/wp-includes/formatting.php on line 2786

The warning was appended to the debug log when opening and refreshing the dashboard.

Change History (6)

This ticket was mentioned in PR #4171 on WordPress/wordpress-develop by tools400.

17 months ago

This little fix removes the following PHP warning from the debug log:

"[04-Mar-2023 10:45:00 UTC] PHP Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /homepages/36/d24807059/htdocs/clickandbuilds/BergsportFamilieRaddatz/wp-includes/formatting.php on line 2786"

Trac ticket:

#2 @johnbillion
17 months ago

  • Keywords reporter-feedback added

Thanks for the PR @tools400, and welcome.

The $value parameter of untrailingslashit() should only ever be a string. Putting this guard in place to avoid a PHP warning when it's null is really just papering over the problem instead of fixing the root cause. It would be better to find and fix the situation in which null gets passed to this parameter in the first place.

Does this error still occur if you deactivate all your plugins and switch to one of the default "Twenty" themes? I think it's quite likely that a plugin or theme on your site is passing null to this function.

Which version of PHP are you using?

#3 @SergeyBiryukov
17 months ago

  • Keywords php81 added

Thanks for the ticket!

As noted above, the steps to reproduce the issue on a clean install would be helpful here.

As far as I can tell, core by itself should no longer throw this notice as of [54349] / #55967, though it's still possible that a plugin or theme passes null instead of a string to this function.

#4 @tools400
17 months ago

Thank you all for your fast reply. I understand your points and I basically agree, that the fix is like papering the actual problem. On the other hand that is the same as what rtrim() does now, but without messing up the debug log.

Nevertheless I suggest closing the pull request. Unfortunately I do not have the time for trying to recreate the problem with a clean WordPress install. And even worse I do not know when that situation will change.

But of course I will get back to you in case that I figure out something new and helpful.

"Which version of PHP are you using?"

My server uses PHP 8.1.16 (

#5 @hellofromTonya
12 months ago

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

Hello @tools400,

Welcome! Thank you for creating the ticket :)

I agree the fix should be in the plugin or theme that is incorrectly passing something other than a string.

Thank you for following up to suggest closing. If in the future you do get time to investigate and find it happens on a clean default site (with no plugins and using a default theme), then please reopen this ticket.

@hellofromTonya commented on PR #4171:

12 months ago

Closing as the function expects only a string. Adding the guard hides the problem and could result in unexpected behavior.

Note: See TracTickets for help on using tickets.