Jump to content

Recommended Posts

hi i am currently trying to laern more about php witch inlcudes trying to work with its oop form. I have come across a few instances where there have been either variables,functiions or methods prepended with either the @ or &.

 

can anyone explain these uses for example

 

i seen something like this

 

@mail ($variable,$variable,$variable)

 

and i have seen this

 

function showBox(&$connector){

    //do something

 

  return result

}

 

what are the meanings of these and the specific uses please

Link to comment
https://forums.phpfreaks.com/topic/71045-solved-leading-characters/
Share on other sites

hi i am currently trying to laern more about php witch inlcudes trying to work with its oop form. I have come across a few instances where there have been either variables,functiions or methods prepended with either the @ or &.

 

can anyone explain these uses for example

 

i seen something like this

 

@mail ($variable,$variable,$variable)

 

and i have seen this

 

function showBox(&$connector){

    //do something

 

  return result

}

 

what are the meanings of these and the specific uses please

 

The '@' tells PHP to not display any errors the function may generate.  The '&' signifies that the variable is being passed-by-reference to the function.  More generically, the '&' always means treat whatever it's attached to like a reference.  So, you can return values by reference, too.  This link explains what references are and how PHP uses them: http://us2.php.net/references

 

EDIT: In PHP 5, everything is pass-by-reference by default, so you don't have to use the '&' to signify it.

ok so & is basically like saying that no matter where the varible is updated give it the most recent value

 

so for instance

 

$bar = 6

$foo = $bar

$bar = 12

 

print $foo // 6

 

$bar = 6

$foo = &$bar

$bar = 12

 

print $foo // 12

 

 

 

if this is correct, then is this affected by scope? or is it referenced by document

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.