Opened 2 years ago
Closed 2 years 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 | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Formatting | Version: | |
| Severity: | normal | Keywords: | has-patch close |
| Cc: | Focuses: | php-compatibility |
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.
2 years ago
#1
- Keywords has-patch added
#3
@
2 years 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
@
2 years ago
- Component General → Formatting
- Milestone Awaiting Review
- Resolution → duplicate
- Status new → 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 '';
}
Thanks Mike!
Another solution would be to set the
$urlparameter 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
'', sinceempty()already checks for that as well.