0

Everything I can find refers to the use of the @ symbol as a prefix to an expression, e.g.:

$foo = @bar();

This is not what I'm talking about here. I have a statement which uses the @ symbol as a prefix to an L-value, like:

@$foo = bar();

What does this mean?

(Ideally, please explain the semantics as a de-sugaring of this statement into one that does not use the @ symbol.)

jameshfisher
  • 34,029
  • 31
  • 121
  • 167
  • Flagged as duplicate. This is covered in the PHP operators reference: http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php and specifically here: http://stackoverflow.com/questions/1032161/what-is-the-use-of-symbol-in-php – AgentConundrum Aug 05 '14 at 13:06

1 Answers1

3

@ symbol is used to suppress error messages

PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.

For example;

The following code doesn't produce any errors on screen;

<?php

ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);

@$foo = $bar;

echo $foo;

However, without the @ it does;

Notice: Undefined variable: bar in C:\xampp\htdocs\test\test.php on line 6

ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • 1
    On the **LHS** of an assignment? – Quentin Aug 05 '14 at 12:56
  • @Quentin:- Yes I think so(Do correct me if I am wrong) I have read this:-`PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.` – Rahul Tripathi Aug 05 '14 at 12:58
  • @R.T. wait -- are you saying that the expression that it precedes is `$foo = bar()`? So the code parses as `@($foo = bar());`? That's certainly one explanation. – jameshfisher Aug 05 '14 at 13:12
  • @jameshfisher:- Indeed! – Rahul Tripathi Aug 05 '14 at 13:19