#57867 closed enhancement (invalid)
Fix PHP warning when passing NULL to rtrim().
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.2 |
Component: | Formatting | Keywords: | has-patch reporter-feedback php81 |
Focuses: | Cc: |
Description
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.
7 months ago
#1
#2
@
7 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
@
7 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
@
7 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 (ionos.de)
#5
@
7 weeks 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:
7 weeks ago
#6
Closing as the function expects only a string. Adding the guard hides the problem and could result in unexpected behavior.
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: https://core.trac.wordpress.org/ticket/57867