Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 4 months ago

#56808 closed enhancement (duplicate)

adding null coalescing operator for rtrim function to avoid deprecation

Reported by: asifmuztaba's profile asifmuztaba 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)

Screenshot_17.png (112.5 KB) - added by asifmuztaba 3 years ago.
Warning Screenshot

Download all attachments as: .zip

Change History (3)

@asifmuztaba
3 years ago

Warning Screenshot

#1 @ocean90
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

Hello @asifmuztaba, welcome to WordPress Trac! Thanks for the report, this has been fixed in [54349] already. Marking as a duplicate of #54997 and #55967.

#2 @jusni5
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.