[wp-hackers] Why pass by reference?

Andrew Nacin wp at andrewnacin.com
Fri Jul 12 20:10:06 UTC 2013


It was necessary in PHP 4, it is no longer necessary in PHP 5.


On Fri, Jul 12, 2013 at 3:59 PM, Micky Hulse <mickyhulse.lists at gmail.com>wrote:

> Hello,
>
> For the second example:
>
> <http://codex.wordpress.org/Function_Reference/add_meta_box#Example>
>
> Why pass $this by reference? Specifically:
>
> array(
>     &$this,
>     'render_meta_box_content',
> ),
>
> Occasionally, I'll see WP example code (like above) where the author
> passes $this by reference.
>
> Other examples, like:
>
> <
> http://codex.wordpress.org/Function_Reference/add_action#Using_add_action_with_a_class
> >
>
> ... $this isn't passed by reference.
>
> Sorry if this is a dumb question, but (within the context of coding
> OOP for WP) how do I determine if I need to pass $this by reference?
> Is there a good WP/PHP rule of thumb?
>
> For the add_meta_box() example, I don't see any obvious reasons why
> passing by reference is required and/or better than not. :D
>
> Thanks!
> M
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list