Make WordPress Core

Opened 4 days ago

Closed 4 days ago

#61544 closed defect (bug) (duplicate)

PHP Deprecated: ltrim(): Passing null to parameter #1 ($string) of type string is deprecated in /app/public/wp-includes/formatting.php on line 4494

Reported by: mikedjo's profile mikedjo Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Formatting Keywords: has-patch close
Focuses: php-compatibility Cc:

Description

Formatting.php :4490

	if ( '' === $url) {
		return $url;
	}

Should be:

	if ( '' === $url || empty($url)) {
		return $url;
	}

to prevent unnecessary deprecation warnings in the debug.log

Change History (4)

This ticket was mentioned in PR #6949 on WordPress/wordpress-develop by @mikedjo.


4 days ago
#1

  • Keywords has-patch added

#2 @robinmartijn
4 days ago

  • Focuses php-compatibility added

Thanks Mike!

Another solution would be to set the $url parameter to have an empty string as the default value. I am not sure if we have a preference regarding that.

If we choose your proposal, we can drop the check for '', since empty() already checks for that as well.

Last edited 4 days ago by robinmartijn (previous) (diff)

#3 @swissspidy
4 days ago

  • Keywords close added

If you get deprecation warnings like this, it's because a plugin or theme is incorrectly passing null values to esc_url. This should be fixed at the root, which is in the plugin/theme making these calls.

#4 @sabernhardt
4 days ago

  • Component changed from General to Formatting
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi and thanks for the patch.

This was already reported on #61268, and the discussion should continue on that ticket.

Please find what code uses esc_url incorrectly before trying to edit the Core function. Editing the esc_url function's condition could result in more links with empty href values that do not give any notice of a failure.

In the proposed patch, if the value of $url evaluates as empty but is not a string, the function would still need to return a string (not the $url value).

	if ( empty( $url ) ) {
		return '';
	}
Note: See TracTickets for help on using tickets.