[wp-hackers] [help] sink plugin hooks for $this
Jamie Talbot
wphackers at jamietalbot.com
Sat Jan 14 13:54:33 GMT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Robert Deaton wrote:
> The problem is that $this is a special variable reserved for being
> called inside the class. You cannot use $this at all outside of the
> context of a class, and doing so will cause errors.
>
> The key to fixing this, is to move the add_action call to the
> constrictor of the class.
>
I know about $this and I'm pretty sure we're saying the same thing. Both of the following methods
are possible. The first is much cleaner, but the second is still valid and works. I wasn't saying
you should do it, just that it could be done!
<?php
class myTestClassA() {
function myTestClassA() { // constructor
add_action('activate_samba/loadbalancer.php', array(&$this, 'install');
}
function install() {
// do install stuff here
}
}
$singletonA = new myTestClassA;
class myTestClassB() {
function myTestClassB() { // constructor
}
function install() {
global $singletonB;
// do install stuff here
}
}
$singletonB = new myTestClassB;
add_action('activate_samba/loadbalancer.php', array('myTestClassB', 'install');
?>
Cheers,
Jamie.
- --
http://jamietalbot.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDyQKZrovxfShShFARAvRzAJ4wzVFY1R9FvMheBGv/guQoVx0cOgCcC2HF
JW/kDFTVNFRyabMD7PKmFG4=
=kzxj
-----END PGP SIGNATURE-----
More information about the wp-hackers
mailing list