WordPress.org

Make WordPress Core

Changeset 40039


Ignore:
Timestamp:
02/03/2017 08:57:38 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Media: In wp_unique_filename(), use explicit type casting when incrementing $number.

This prevents the "non-numeric value encountered" warning in PHP 7.1, caused by trying to increment an empty string on the first loop iteration.

Props drrobotnik for initial patch.
Fixes #39774.

File:
1 edited

Legend:

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

    r40030 r40039  
    20642064            // Check for both lower and upper case extension or image sub-sizes may be overwritten.
    20652065            while ( file_exists($dir . "/$filename") || file_exists($dir . "/$filename2") ) {
    2066                 $new_number = $number + 1;
     2066                $new_number = (int) $number + 1;
    20672067                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-$new_number$ext", $filename );
    20682068                $filename2 = str_replace( array( "-$number$ext2", "$number$ext2" ), "-$new_number$ext2", $filename2 );
     
    20842084
    20852085        while ( file_exists( $dir . "/$filename" ) ) {
     2086            $new_number = (int) $number + 1;
    20862087            if ( '' == "$number$ext" ) {
    2087                 $filename = "$filename-" . ++$number;
     2088                $filename = "$filename-" . $new_number;
    20882089            } else {
    2089                 $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . ++$number . $ext, $filename );
     2090                $filename = str_replace( array( "-$number$ext", "$number$ext" ), "-" . $new_number . $ext, $filename );
    20902091            }
     2092            $number = $new_number;
    20912093        }
    20922094    }
Note: See TracChangeset for help on using the changeset viewer.