I'm trying to wrap my head around the idea of having a function return a reference. I understand that if you pass a variable by reference, any changes made to that variable within the function will be reflected in that variable rather than making a copy.
At first I thought that returning by reference meant that if a variable was set to reference a function return, that whenever that function was run that variable would change to the returned value, but I haven't been able to get to this to work which lead me to a new assumption. Returning by reference is only used when the variable being referenced in the return has a scope that is outside the function. Meaning that returning a reference for a local variable is useless. So it's used with global variables and with object properties.
Is any of this correct? Sorry if this is confusing, I'm probably thinking about it too much. I'm just trying to figure out when and how it's used.
EDIT
I know my join date shows that I should probably have picked this up by now, but the truth is I'm more of a designer who's dabbled in PHP over the years. I'm trying to finally I pick it up since it would be valuable to be able to write some of my own scripts and applications.