Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 300
user2406612 Avatar asked Oct 24 '25 11:10

user2406612


2 Answers

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;
});
like image 152
Alex Barker Avatar answered Oct 26 '25 02:10

Alex Barker


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

like image 30
Amit Sharma Avatar answered Oct 26 '25 01:10

Amit Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!