怎样解决 PHP 里 Deprecated: Function create_function() is deprecated 的问题? | How to solve “create_function() is deprecated” issue in PHP

最近使用wordpress的时候碰到一个php的问题, 比如一个theme里面运行时出现这个不知道是error还是warning的message

Deprecated: Function create_function() is deprecated in /mypath/myfile.php on line 20
add_action('widgets_init', create_function('', 'return register_widget("mywidget");'));

Google了一下貌似是create_function这种写法过时了. 把它改成lambda, 也就是anonymous 就解决了

add_action(
  'widgets_init', 
  function() { 
    return register_widget("mywidget");
  }
);

Leave a Comment

Your email address will not be published.