phpphp-7.2create-function

PHP 7.2 error Function create_function() is deprecated


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!


Solution

  • 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;
    });