2

Any suggestions as to how to change the last line in this code so it won't throw a "deprecated function" alert in the log?

function make_plural_form_function($nplurals, $expression) {
    $expression = str_replace('n', '$n', $expression);
    $func_body = "
        \$index = (int)($expression);
        return (\$index < $nplurals)? \$index : $nplurals - 1;";
    return create_function('$n', $func_body);

Thank you for your help

EaZy
  • 33
  • 2
  • 4

1 Answers1

3

The create_function was deprecated in PHP7.2

This below code may help you.

function make_plural_form_function($nplurals, $expression) {
    $expression = str_replace('n', '$n', $expression);
    $func_body = "
        \$index = (int)($expression);
        return (\$index < $nplurals)? \$index : $nplurals - 1;";
    $createFun =  function($n){
        return $func_body;
    };     
    return $createFun;
}

Thanks.

Ramya
  • 199
  • 10