Jump to content

[SOLVED] leading characters?


Stickybomb

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

Archived

This topic is now archived and is closed to further replies.

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