Make WordPress Core

Changeset 49073


Ignore:
Timestamp:
09/30/2020 12:18:36 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Check if the file to retrieve metadata from in get_file_data() was successfully opened.

This avoids a fatal error on PHP 8 caused by passing a false value to fread(), instead of a file resource.

See #50913.

File:
1 edited

Legend:

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

    r49055 r49073  
    60416041        $fp = fopen( $file, 'r' );
    60426042
    6043         // Pull only the first 8 KB of the file in.
    6044         $file_data = fread( $fp, 8 * KB_IN_BYTES );
    6045 
    6046         // PHP will close file handle, but we are good citizens.
    6047         fclose( $fp );
     6043        if ( $fp ) {
     6044                // Pull only the first 8 KB of the file in.
     6045                $file_data = fread( $fp, 8 * KB_IN_BYTES );
     6046
     6047                // PHP will close file handle, but we are good citizens.
     6048                fclose( $fp );
     6049        } else {
     6050                $file_data = '';
     6051        }
    60486052
    60496053        // Make sure we catch CR-only line endings.
Note: See TracChangeset for help on using the changeset viewer.