& $ this in Wordpress add_action callback

I just pee my feet in Wordpress, and I'm trying to write a very simple plugin using OOP methods. I follow this guide: http://www.yaconiello.com/blog/how-to-write-wordpress-plugin/ . So far, I feel like I understand most of what is happening, but I'm a little puzzled by statements like this:

add_action('init', array(&$this, 'init')); 

After reading the Wordpress documentation add_action () and PHP, I think the second argument is the class instance method. But I do not understand why it $thisshould be passed by reference .

This note was discovered in PHP docs about calling messages that I suspect might have something to do with it, but it's still hard for me to turn my head around, what is the difference:

Note. In PHP 4, you had to use a link to create a callback pointing to the actual object, not a copy of it. For more information, see the Links section.

If I have PHP 5, am I just using array($this,'init')?

Perhaps related: add_action in Wordpress using OOP?

+3
source share
1 answer

Yes - you can just use it array($this, 'init');.

That this is actually "callable" in PHP. It will be called using call_user_func()or call_user_func_array()(inside the method add_action).

PHP :

, 0 1.

.

+2

All Articles