怎樣解決 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.