Discussion:
Why pass by reference?
Micky Hulse
2013-07-12 19:59:59 UTC
Permalink
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
Andrew Nacin
2013-07-12 20:10:06 UTC
Permalink
It was necessary in PHP 4, it is no longer necessary in PHP 5.
Post by Micky Hulse
Hello,
<http://codex.wordpress.org/Function_Reference/add_meta_box#Example>
array(
&$this,
'render_meta_box_content',
),
Occasionally, I'll see WP example code (like above) where the author
passes $this by reference.
<
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
http://lists.automattic.com/mailman/listinfo/wp-hackers
Micky Hulse
2013-07-12 20:12:42 UTC
Permalink
Post by Andrew Nacin
It was necessary in PHP 4, it is no longer necessary in PHP 5.
Ahhh, good to know! Thank you for the clarification Andrew, I really
appreciate it! :)

Have a nice day.

Cheers,
Micky

Loading...