Make WordPress Core


Ignore:
Timestamp:
08/13/2020 12:32:03 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Change create_function() in phpunit/includes/plural-form-function.php to closure.

create_function() has been deprecated in PHP >= 7.2 and removed in PHP 8.

The only instance left in core was used in a test that was being skipped on PHP >= 7.2. This allows the test to run again.

Follow-up to [41722], [41730].

Props jrf.
Fixes #50899.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/plural-form-function.php

    r46586 r48790  
    88 */
    99function tests_make_plural_form_function( $nplurals, $expression ) {
    10         $expression = str_replace( 'n', '$n', $expression );
    11         $func_body  = "
    12                 \$index = (int)($expression);
    13                 return (\$index < $nplurals)? \$index : $nplurals - 1;";
     10        $closure = function ( $n ) use ( $nplurals, $expression ) {
     11                $expression = str_replace( 'n', $n, $expression );
    1412
    15         // phpcs:ignore WordPress.PHP.RestrictedPHPFunctions.create_function_create_function
    16         return create_function( '$n', $func_body );
     13                // phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
     14                $index = (int) eval( 'return ' . $expression . ';' );
     15
     16                return ( $index < $nplurals ) ? $index : $nplurals - 1;
     17        };
     18
     19        return $closure;
    1720}
Note: See TracChangeset for help on using the changeset viewer.