Make WordPress Core

Opened 17 months ago

Closed 17 months ago

Last modified 16 months ago

#63625 closed enhancement (invalid)

esc_url and other - Clarify behavior on legacy PHP 8.0+ errors in edge cases

Reported by: alexanderkoledov Owned by:
Priority: normal Milestone:
Component: General Version: 6.8
Severity: normal Keywords: has-patch close
Cc: Focuses:

Description

Hi,

We have esc_url function that expects a string as an argument for ltrim to work correctly. Before php 8, when receiving an array, this did not cause a Fatal Error. How about protecting yourself from a Fatal error and a site crash, for example, like this

<?php
function esc_url( $url, $protocols = null, $_context = 'display' ) {
    if ( ! is_string( $url ) ) {
        return '';
    }

    $url = ltrim( $url );
    // ...
}

Yes, I understand that this may look like a masking of the problem and in the end passing correct data to the function is a task that the developer should take care of, but here I think the gain from reliability is greater. Given that WordPress strives for backward compatibility and developer convenience, I believe this small adjustment would improve overall reliability and user experience.

Thanks for considering.

Attachments (1)

esc_url-php8-safety.patch​ (323 bytes ) - added by alexanderkoledov 17 months ago.

Download all attachments as: .zip

Change History (4)

#1 @johnbillion
17 months ago

  • Keywords close added

Thanks for the ticket and the patch @alexanderkoledov. The problem with this approach is it almost completely masks the problem, which can be more harmful in the long term. There are likely dozens of functions in WordPress which exhibit similar behaviour when passed an incorrect type in PHP 8.

Given that PHP 8 was released nearly five years ago, I don't think it's a good idea to make this change now.

#2 @alexanderkoledov
17 months ago

  • Resolution → invalid
  • Status new → closed
  • Summary esc_url → esc_url and other - Clarify behavior on legacy PHP 8.0+ errors in edge cases

#3 @sabernhardt
16 months ago

  • Milestone Awaiting Review
Note: See TracTickets for help on using tickets.