views:

155

answers:

1

I have 3 classes in WordPress (the question itself is unrelated to it):

class WP_Widget

class Theme_Widget extends WP_Widget

class Specific_Widget extends Theme_Widget

Essentially Theme_Widget contains some extension functions to the basic WP_Widget.

Inside Specific_Widget I call one of Theme_Widget's methods:

class Specific_Widget {

    function __construct() {
         $this->some_method_that_belongs_to_Theme_Widget();
    }
}

When I instantiate Specific_Widget, PHP throws a fatal error as follows:

Fatal error: Call to private method Theme_Widget::some_method_that_belongs_to_Theme_Widget() from context 'Specific_Widget' in ...

Do you have an idea as to how I can resolve this? This is the first time I've received this error from PHP. Could it be derive from WordPress itself?

+1  A: 

You must declare your method protected, rather than private, if you wish child classes to be able to use it.

TheDeadMedic
All methods are declared "public", so there shouldn't have been a problem (but anyways I tried protected and it didn't work either).
sombe
@sombe - the method you're trying to call in Theme_Widget hast to be protected - not private.
jlindenbaum
@jlindenbaum I said I tried both public and protected and it didn't work either.
sombe
Are you sure they are public? That error specifically mentions that `some_method_that_belongs_to_Theme_Widget` is private.
TheDeadMedic
I realize that. I'm not new to PHP that's why it seemed very weird. I've dabbling with the classes and it seems WordPress is responsible for this. Why that happens is beyond me...
sombe
I think without a little more code we might not be able to solve anything. Technically there shouldn't be any problems with protection, since WP only uses simple PHP4 OO.
TheDeadMedic