section31 Posted March 16, 2005 Posted March 16, 2005 (edited) I know about the usage of references to variables, but i've never seen them used on functions like this. >function &getFoobar() { // code return $data; } and on the script its called with the ampersand like this. $contents = &getFoobar(); 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. Edited March 16, 2005 by section31 Quote
section31 Posted March 16, 2005 Author Posted March 16, 2005 (edited) 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. 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? Edited March 16, 2005 by section31 Quote
borfast Posted March 16, 2005 Posted March 16, 2005 Functions may return references or copies of their results, depending on how you declare them. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.