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


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

  • You might be looking for parent::__construct(), but that's just a guess. – hakre May 31 '12 at 7:29
  • @hakre That's not what the OP was asking about. – scribu May 31 '12 at 14:31
  • 1
    I mean that widget_name::__construct() call parent::__construct() directly. – hakre May 31 '12 at 14:36
  • @hakre Oh, I see. Yeah, that might work. – scribu Jun 1 '12 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.