#56808 closed enhancement (duplicate)
adding null coalescing operator for rtrim function to avoid deprecation
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
There was a warning showing
Deprecated: rtrim(): Passing null to parameter #1 ($string) of type string is deprecated in /var/www/html/wordpress/wordpress/wp-includes/formatting.php on line 2872
The rtrim function 1st parameter value as null is deprecated in php 8.1. It can be fixed by adding
null coalescing
operator.
function untrailingslashit( $string ) { return rtrim( $string ?? '', '/\\' ); }
Attachments (1)
Change History (3)
#1
@
3 years ago
- Keywords changes-requested needs-testing removed
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
- Version 6.0.2 deleted
#2
@
4 months ago
The warning you're encountering is due to a change in PHP 8.1, where passing null to the first parameter of the rtrim() function is deprecated. The proposed fix using the null coalescing operator (??) is correct and ensures that the function behaves as expected without triggering the deprecation warning.
Note: See
TracTickets for help on using
tickets.
Warning Screenshot