[wp-hackers] Class function in Hook
Mike O'Malley
spuriousdata at gmail.com
Sat Aug 15 23:39:39 UTC 2009
On Sat, Aug 15, 2009 at 7:23 PM, John Kolbert <list at johnkolbert.com> wrote:
>
> // First
> $bf_vendor = new bf_vendor();
>
> register_activation_hook(__FILE__, array(&$bf_vendor,
> 'installTable'));
In the first, $bf_vendor is an instance of the class bf_vendor(); $bf_vendor
has it's own copy of any non-static member variables that are defined in the
class, and the method installTable() should probably only operate on those.
This loosely translates to: $bf_vendor->installTable();
> // Second
>
> register_activation_hook(__FILE__, array('bf_vendor',
> 'installTable'));
>
>
In the second, you are registering installTable to be called as a static
method of the class bf_vendor. This loosely translates to:
bf_vendor::installTable();
> Both of these methods seemed to work. I was just wondering if there is any
> difference or preferred method between the two. Thanks guys.
If that is the case, you most likely don't have any non-instance member
variables of the class bf_vendor(). Which versions of php and which
configurations of php.ini support referencing static members/methods as
instance members/methods currently escapes me, but in general, it should be
avoided.
For more information:
http://us2.php.net/manual/en/language.oop5.static.php
and
http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback
--
Mike
More information about the wp-hackers
mailing list