4

After upgrade my VPS to PHP 7.2, my website have this error:

PHP Deprecated: Function create_function() is deprecated in /home/nickname/public_html/framework/web/CHttpRequest.php on line 968

and the code at this file its:

usort($languages,create_function('$a,$b','if($a[0]==$b[0]) {return 0;} return ($a[0]<$b[0]) ? 1 : -1;'));

I'm not sure how to fix it, please help me, thanks!

1

2 Answers 2

6

Should be as simple as replacing the function call with an anonymous function.

usort($languages, function($a, $b) {
    if($a[0] == $b[0]) {
        return 0;
    }
    return $a[0] < $b[0] ? 1 : -1;
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the create_function as the callback function for earlier versions of php but now the create_function has been deprecated from the php7.2 and you need to use an anonymous function as @Alex Barker mentioned. Here is the link where you can see the deprecated function create_function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.