tags:

views:

100

answers:

3

i using word press, and i try to learn it, but is see the code which i didn't understand

$post = &get_post($id);

i see '&' before the get_post, what is '&' meaning?

thank

+5  A: 

Passing or assigning by reference.

Crayon Violent
+7  A: 

Here you're getting a reference to the result of get_post($id).

In particular you're using the "returning by reference" technique.

Returning References :

Returning by reference is useful when you want to use a function to find to which variable a reference should be bound.


The same syntax can be used with functions that return references, and with the new operator (since PHP 4.0.4 and before PHP 5.0.0):

  <?php
  $foo =& find_var($bar);
  ?>

Since PHP 5, new returns a reference automatically, so using =& in this context is deprecated and produces an E_STRICT message.

So if you're using >= PHP 5 it's not a really great idea to use this notation.


Resources :

Colin Hebert
Sorry for my late reply, i'm really happy with this explanation. you include the example of case.. best answer :D
GusDe CooL
+1  A: 

Now you already know that is for return by reference, next things is the effect of that. The effect will be this: Whenever you change $post variable's value, you are actually changing the get_post($id) content. get_post() return object having all the info about that post in database.

Satya Prakash