MyBB Community Forums

Full Version: Objects passed as argument's for plugin hooks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to write a plugin that uses this hook:
$plugins->run_hooks_by_ref("datahandler_user_insert", $this);

And I'm wondering how to work with the "$this" object inside my plugin code.

I've declared my plugin function properly as
function plugin_user_insert($this)

But when I try and access the data, for instance the username:
$this->user_insert_data['username']

It fails. I'm not at home right now, so I can't see the errors being generated (I intend to fix my access to the logs later) and I'm hoping someone can tell me what I'm missing. I don't often work with objects in php (in fact, only with MyBB do I on any kind of frequent basis), so I'm probably just missing something obvious.
Here:
function plugin_user_insert($this) 

$this can be anything else but try the following:
Try:
function plugin_user_insert(&$myobject) 

And don't forget the add_hooks part (you did that right?)
Yeah, I've got the add_hook part Wink
It gets into the function just fine, but when I try and use it (the object $this) it pukes is all.

I'm too used to C. :|

Anyways, thanks, and I'll give it a try shortly.
If it doesn't work, try accessing $this->data directly, instead of $this->user_insert_data.
Note that members of the array data haven't been escaped, only in user_insert_data
Yup, thats why I was trying to use user_insert_data...

All that was doing wrong in the end was trying to use $this as the varname. I had tried to do &$this in the function call, but it puked out too. However &$obj worked fine. Thanks Pirata.
Okay, glad it works now Smile
$this is one of those super-duper variables that can't be assigned outside of a class. I think, or something along that line...
if ( I could more easily [i]understand[/i] $this--> function plugin_user_insert(&$myobject) ) {
	echo "Then my life would be better, and things would be easier.";
} else {
	echo "Keep wasting too much time.";
}
Rolleyes
(2009-12-18, 04:58 PM)Tomm M Wrote: [ -> ]$this is one of those super-duper variables that can't be assigned outside of a class. I think, or something along that line...

Yeah, like I said... too stinking used to C lol! But thanks for that tidbit too.