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!

user2406612
  • 51
  • 1
  • 5
  • Does this answer your question? [PHP 7.2 Function create\_function() is deprecated](https://stackoverflow.com/questions/48161526/php-7-2-function-create-function-is-deprecated) – Calos Jan 15 '20 at 03:25

2 Answers2

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;
});
Alex Barker
  • 4,316
  • 4
  • 28
  • 47
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

Amit Sharma
  • 1,775
  • 3
  • 11
  • 20