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
  • 16,135
  • 16
  • 55
  • 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."

Problematic
  • 17,567
  • 10
  • 73
  • 85
2

@ means "don't report errors"

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

sblom
  • 26,911
  • 4
  • 71
  • 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,520
  • 3
  • 23
  • 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
  • 11,584
  • 3
  • 57
  • 71