Jump to content

Recommended Posts

Posted (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 by section31
Posted (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. :xmas:

 

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 by section31

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...