WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 5 down vote accepted

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

share|improve this answer
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
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 posting your answer, you agree to the privacy policy and terms of service.

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