[wp-hackers] Odd behaviour when using classes and the register_activation_hook() function

John Blackbourn johnbillion+wp at gmail.com
Thu Dec 4 02:25:41 GMT 2008


I've come across this odd issue and I'm not sure if I'm doing
something wrong, so would appreciate any pointers.

I am writing a plugin which uses register_activation_hook() to call a
function when the plugin is activated. From within the function that
gets called, another function is called which is a member function of
a class defined in the plugin.

I've cut the plugin down to the very minimum needed to demonsrate the
code. See: http://johnblackbourn.com/temp/helloworld.phps .

The problem I am seeing is that when the plugin is activated, this
calling of the class member function is causing a fatal error.

"Fatal error: Cannot redeclare activatehelloworld() (previously
declared in [snip] )"

Now, if we remove the line $helloworld->hello(); then all is fine and
the plugin can be activated with no errors. If we instead call another
function here that is not a class member function, all is fine. It
appears that the act of calling a class member function at this point
is doing something strange, or more likely, is acting in a manner that
I don't understand.

It might also be worth mentioning that, oddly enough, the plugin is
actually activated despite this error being shown. This may be related
or it may be a red herring.

I'm stumped. I cannot see any reason why calling a class member
function at this point would produce this error. Anyone?

John.


More information about the wp-hackers mailing list