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

1
  • I've read this thread. Cannot adapt the answer to my code though Commented Jan 3, 2019 at 11:45

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.