Friday, January 30, 2026
HomeLanguagesWhat is the use of the @ symbol in PHP?

What is the use of the @ symbol in PHP?

The at sign (@) is used as error control operator in PHP. When an expression is prepended with the @ sign, error messages that might be generated by that expression will be ignored. If the track_errors feature is enabled, an error message generated by the expression and it will be saved in the variable $php_errormsg. This variable will be overwritten on each error.

Program 1:




<?php
  
// File error 
$file_name = @file ('non_existent_file') or
    die ("Failed in opening the file: error: '$errormsg'");
  
// It is used for expression
$value = @$cache[$key];
  
// It will not display notice if the index $key doesn't exist.
  
?>


RunTime Error:

PHP Notice:  Undefined variable: errormsg in /home/fe74424b34d1adf15aa38a0746a79bed.php on line 5

Output:

Failed in opening the file: error: ''

Program 2:




<?php
  
// Statement 1
$result= $hello['123']
  
// Statement 2
$result= @$hello['123']
?>


It will execute only statement 1 and display the notice message

PHP Notice:  Undefined variable: hello.

Note: The use of @ is very bad programming practice as it does not make error disappear, it just hides them, and it makes debugging a lot worse since we can’t see what’s actually wrong with our code.

References: Error Control Operators

RELATED ARTICLES

Most Popular

Dominic
32478 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6849 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6987 POSTS0 COMMENTS
Ted Musemwa
7222 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6917 POSTS0 COMMENTS