Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top