Php Function References?

liunx

Guest
I know about the usage of references to variables, but i've never seen them used on functions like this.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->function &getFoobar() {<br />     // code<br />     return $data;<br />}<!--c2--></div><!--ec2--><br /><br />and on the script its called with the ampersand like this. <br /><br />$contents = &getFoobar();<br /><br />Can someone shed some light on this for me. I was thinking that it could just return a reference of the data thats returned but that wouldn't make sense since its destroyed when the function call is complete.<!--content-->
First, What happened to the edit feature...I couldn't find it...lol Don't tell me these boards have it set where you can only edit within the first few minutes. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/mad.gif" style="vertical-align:middle" emoid=":angry:" border="0" alt="mad.gif" /> <br /><br />Next, let me revise my question. I just realized that by sending a reference and destroying the variable doesn't mean the data will be lost. I guess now my question is, don't functions always return references or do they return copies. If its the latter, i think i can understand why it would be beneficial to return a reference rather than a copy... Efficiency purposes, right?<!--content-->
Functions may return references or copies of their results, depending on how you declare them.<!--content-->
 
Back
Top