开发者

What is '&' meaning in this php code

开发者 https://www.devze.com 2023-01-17 10:29 出处:网络
i using word press, and i try to learn it, but is see the code which i didn\'t unde开发者_Python百科rstand

i using word press, and i try to learn it, but is see the code which i didn't unde开发者_Python百科rstand

$post = &get_post($id);

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

thank


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 :

  • php.net - references


Passing or assigning by reference.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消