Title: replace create_function for PHP 8
Last modified: November 24, 2022

---

# replace create_function for PHP 8

 *  Resolved [eagerbob](https://wordpress.org/support/users/eagerbob/)
 * (@eagerbob)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/)
 * Hello all,
 * A website that I installed long ago has stopped working. Turns out that the theme
   uses `create_function` that has been removed from PHP 8.0
    I looked it up and
   there are examples of how to rewrite the code, but I can’t get it to work.
 * This is the offender:
 * `add_action( 'widgets_init', create_function( '', 'register_widget("Zilla_Twitter_Widget");'));`
 * So how could this line be re-written so that it works with PHP 8.0 ?
 * Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [hirenbhanderi](https://wordpress.org/support/users/hirenbhanderi/)
 * (@hirenbhanderi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/#post-16233169)
 * Yes this problem has occurred because this function has been removed from PHP
   8,this problem solution is
 * function fn_Zilla_Twitter_Widget() {
    register_widget( ‘Zilla_Twitter_Widget’);}
   add_action( ‘widgets_init’, ‘fn_Zilla_Twitter_Widget’);
 *  Thread Starter [eagerbob](https://wordpress.org/support/users/eagerbob/)
 * (@eagerbob)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/#post-16233622)
 * OK Thanks Hiren for your quick response.
 * Unfortunately I still get an error:
 * `Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::
   __construct(), 0 passed in /Users/eagerbob/Local Sites/cinetone/app/public/wp-
   includes/class-wp-widget-factory.php on line 62 and at least 2 expected in /Users/
   eagerbob/Local Sites/cinetone/app/public/wp-includes/class-wp-widget.php:163 
   Stack trace: #0 /Users/eagerbob/Local Sites/cinetone/app/public/wp-includes/class-
   wp-widget-factory.php(62): WP_Widget->__construct() #1 /Users/eagerbob/Local 
   Sites/cinetone/app/public/wp-includes/widgets.php(115): WP_Widget_Factory->register(‘
   zilla_FLICKR_Wi…’) #2 /Users/eagerbob/Local Sites/cinetone/app/public/wp-content/
   themes/cinetone/includes/widgets/widget-flickr.php(21): register_widget(‘zilla_FLICKR_Wi…’)#
   3 /Users/eagerbob/Local Sites/cinetone/app/public/wp-includes/class-wp-hook.php(
   308): zilla_flickr_widgets(”) #4 /Users/eagerbob/Local Sites/cinetone/app/public/
   wp-includes/class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) #5 /Users/
   eagerbob/Local Sites/cinetone/app/public/wp-includes/plugin.php(517): WP_Hook-
   >do_action(Array) #6 /Users/eagerbob/Local Sites/cinetone/app/public/wp-includes/
   widgets.php(1854): do_action(‘widgets_init’) #7 /Users/eagerbob/Local Sites/cinetone/
   app/public/wp-includes/class-wp-hook.php(308): wp_widgets_init(”) #8 /Users/eagerbob/
   Local Sites/cinetone/app/public/wp-includes/class-wp-hook.php(332): WP_Hook->
   apply_filters(NULL, Array) #9 /Users/eagerbob/Local Sites/cinetone/app/public/
   wp-includes/plugin.php(517): WP_Hook->do_action(Array) #10 /Users/eagerbob/Local
   Sites/cinetone/app/public/wp-settings.php(617): do_action(‘init’) #11 /Users/
   eagerbob/Local Sites/cinetone/app/public/wp-config.php(91): require_once(‘/Users/
   eagerbob’) #12 /Users/eagerbob/Local Sites/cinetone/app/public/wp-load.php(50):
   require_once(‘/Users/eagerbob’) #13 /Users/eagerbob/Local Sites/cinetone/app/
   public/wp-admin/admin.php(34): require_once(‘/Users/eagerbob’) #14 /Users/eagerbob/
   Local Sites/cinetone/app/public/wp-admin/index.php(10): require_once(‘/Users/
   eagerbob’) #15 {main} thrown in /Users/eagerbob/Local Sites/cinetone/app/public/
   wp-includes/class-wp-widget.php on line 163′
 * Seems I’ll have to dive a bit deeper for this.
 * Found some info on Stackexchange: [https://wordpress.stackexchange.com/questions/383777/too-few-arguments-to-function-wp-widget-construct/383778#383778](https://wordpress.stackexchange.com/questions/383777/too-few-arguments-to-function-wp-widget-construct/383778#383778)
 * Thanks again
    -  This reply was modified 3 years, 6 months ago by [eagerbob](https://wordpress.org/support/users/eagerbob/).
      Reason: redacted code
 *  [hirenbhanderi](https://wordpress.org/support/users/hirenbhanderi/)
 * (@hirenbhanderi)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/#post-16233777)
 * yes one little changes in this code you can change one function name.
    Zilla_Twitter_Widget()
   to __construct()
    -  This reply was modified 3 years, 6 months ago by [hirenbhanderi](https://wordpress.org/support/users/hirenbhanderi/).
 *  Thread Starter [eagerbob](https://wordpress.org/support/users/eagerbob/)
 * (@eagerbob)
 * [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/#post-16240947)
 * Ok I changed the code following the information on [developer.wordpress](https://developer.wordpress.org/reference/functions/register_widget/)
   but I kept getting errors. Like a “unmatched “}” at the end of my file. Which
   seems easy to fix but wasn’t.
 * I “Solved” it by removing the widgets alltogether. It was a Flickr and a twitter
   widget, both are not used.
 * Thanks

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘replace create_function for PHP 8’ is closed to new replies.

## Tags

 * [php 8](https://wordpress.org/support/topic-tag/php-8/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [eagerbob](https://wordpress.org/support/users/eagerbob/)
 * Last activity: [3 years, 6 months ago](https://wordpress.org/support/topic/replace-create_function-for-php-8/#post-16240947)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
