WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/15/2019 05:07:20 AM (9 months ago)
Author:
pento
Message:

Code Modernisation: Remove the array_replace_recursive() polyfill.

This function was added in PHP 5.3.0, so we no longer need the polyfill.

Props jrf.
See #47698.

File:
1 edited

Legend:

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

    r45611 r45636  
    450450}
    451451
    452 if ( ! function_exists( 'array_replace_recursive' ) ) :
    453     /**
    454      * PHP-agnostic version of {@link array_replace_recursive()}.
    455      *
    456      * The array_replace_recursive() function is a PHP 5.3 function. WordPress
    457      * currently supports down to PHP 5.2, so this method is a workaround
    458      * for PHP 5.2.
    459      *
    460      * Note: array_replace_recursive() supports infinite arguments, but for our use-
    461      * case, we only need to support two arguments.
    462      *
    463      * Subject to removal once WordPress makes PHP 5.3.0 the minimum requirement.
    464      *
    465      * @since 4.5.3
    466      *
    467      * @see https://secure.php.net/manual/en/function.array-replace-recursive.php#109390
    468      *
    469      * @param  array $base         Array with keys needing to be replaced.
    470      * @param  array $replacements Array with the replaced keys.
    471      *
    472      * @return array
    473      */
    474     function array_replace_recursive( $base = array(), $replacements = array() ) {
    475         foreach ( array_slice( func_get_args(), 1 ) as $replacements ) {
    476             $bref_stack = array( &$base );
    477             $head_stack = array( $replacements );
    478 
    479             do {
    480                 end( $bref_stack );
    481 
    482                 $bref = &$bref_stack[ key( $bref_stack ) ];
    483                 $head = array_pop( $head_stack );
    484 
    485                 unset( $bref_stack[ key( $bref_stack ) ] );
    486 
    487                 foreach ( array_keys( $head ) as $key ) {
    488                     if ( isset( $key, $bref ) &&
    489                         isset( $bref[ $key ] ) && is_array( $bref[ $key ] ) &&
    490                         isset( $head[ $key ] ) && is_array( $head[ $key ] ) ) {
    491 
    492                         $bref_stack[] = &$bref[ $key ];
    493                         $head_stack[] = $head[ $key ];
    494                     } else {
    495                         $bref[ $key ] = $head[ $key ];
    496                     }
    497                 }
    498             } while ( count( $head_stack ) );
    499         }
    500 
    501         return $base;
    502     }
    503 endif;
    504 
    505452/**
    506453 * Polyfill for the SPL autoloader. In PHP 5.2 (but not 5.3 and later), SPL can
Note: See TracChangeset for help on using the changeset viewer.