Wordpress/tests/phpunit/includes/plural-form-function.php
Sergey Biryukov f0733600c9 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.

git-svn-id: https://develop.svn.wordpress.org/trunk@48790 602fd350-edb4-49c9-b593-d223f7449a82
2020-08-13 12:32:03 +00:00

21 lines
498 B
PHP

<?php
/**
* Legacy plural form function.
*
* @param int $nplurals
* @param string $expression
*/
function tests_make_plural_form_function( $nplurals, $expression ) {
$closure = function ( $n ) use ( $nplurals, $expression ) {
$expression = str_replace( 'n', $n, $expression );
// phpcs:ignore Squiz.PHP.Eval -- This is test code, not production.
$index = (int) eval( 'return ' . $expression . ';' );
return ( $index < $nplurals ) ? $index : $nplurals - 1;
};
return $closure;
}