Make WordPress Core

Changeset 52085


Ignore:
Timestamp:
11/09/2021 10:58:39 PM (3 months ago)
Author:
hellofromTonya
Message:

HTTP API: Ensure value returned from 'http_allowed_safe_ports' is an array to avoid PHP 8+ TypeError fatal error.

Adds an is_array() check before the in_array(). Why? in_array() requires a array for the haystack. Any other data type will cause a fatal error on PHP 8.0 or higher:

Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array

As this is a new filter, this type check properly guards to avoid the fatal error.

Follow-up to [52084].

See #54331.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/http.php

    r52084 r52085  
    594594     */
    595595    $allowed_ports = apply_filters( 'http_allowed_safe_ports', array( 80, 443, 8080 ), $host, $url );
    596     if ( in_array( $port, $allowed_ports, true ) ) {
     596    if ( is_array( $allowed_ports ) && in_array( $port, $allowed_ports, true ) ) {
    597597        return $url;
    598598    }
Note: See TracChangeset for help on using the changeset viewer.