0

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I've seen in PHP some variables that are set like this:

$var = @$something;

Or functions set like this:

$var = &my_function();

What effect do the @ and the & have?

Community
  • 1
  • 1
Calvin Froedge
  • 15,505
  • 14
  • 53
  • 61

4 Answers4

5

You have them backwards. &$variable means "a reference to this variable." @my_function() means "call this function and suppress any errors or warnings that it produces."

Derek Stobbe
  • 17,381
  • 10
  • 75
  • 85
2

@ means "don't report errors"

& means "take a reference to the following variable instead of copying its value"

sblom
  • 26,257
  • 4
  • 67
  • 95
2

@ operator in php is used to ignore errors in that statement. Manual: http://www.php.net/manual/en/language.operators.errorcontrol.php

& is reference operator. Manual: http://www.php.net/manual/en/language.references.whatdo.php

Marius Grigaitis
  • 2,480
  • 3
  • 20
  • 30
1

@ causes to hide all errors. In case of variables, it might be E_NOTICE informing about variable not existing.

The &my_function(); is invalid - & is normally used for references, it doesn't nothing in this case.

Konrad Borowski
  • 10,745
  • 3
  • 55
  • 71