Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of such function definition in wordpress "function &get_post" [duplicate]

I am working on wordpress research recently and trying to dig how the query mechanism is handled.
I came across a function definition like this
function &get_post(&$post, $output = OBJECT, $filter = 'raw')
I have not seen anything similar before and not sure if the ampersand(&) has to do something with the address.(Thinking traditionally the use of ampersand(&) ).
I am naive in this and spare me if its something easy.
Can anyone give their thoughts on this.It would help me in moving forward.Tried to find it through google and documentation but did not get find a solution.
Thanks

like image 994
KillABug Avatar asked Oct 05 '22 21:10

KillABug


1 Answers

The first & on the function declaration causes PHP to return a reference. The & on $post makes changes to the actual variable that you pass into the function.

It's actually unclear to me why either of these (the reference declarations) are used. It seems to me to be an incorrect attempt at optimization on Wordpress' part, or it is more likely for compatibility with PHP 4. I think you can just ignore the ampersands for your purposes.

like image 159
Explosion Pills Avatar answered Oct 10 '22 02:10

Explosion Pills