Why will using __construct instead of widget_class_name when creating widget trigger out of memory error

I find that if I use

class widget_name extends WP_Widget {
    function __construct() { ... }
}

instead of

class widget_name extends WP_Widget {
    function widget_name() { ... }
}

I get an error like

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 523800 bytes) in /var/www/vhosts/klifmedia.net/httpdocs/jm/km/wp-content/themes/km/functions.php on line 77

1 Answer
1

Because widget_name::__construct() calls WP_Widget::WP_Widget(), which in turn calls widget_name::__construct() etc.

A simple solution would be to make widget_name::__construct() call WP_Widget::__construct() directly.

Also see http://core.trac.wordpress.org/ticket/16768#comment:9

Leave a Comment