Computer >> Computer tutorials >  >> Programming >> PHP

PHP Error Control Operator


Introduction

In PHP @ symbol is defined as Error Control Operator. When it is prefixed to any expression, any error encountered by PHP parser while executing it will be suppressed and the expression will be ignored.

Following code tries to open a non-existing file for read operation, but PHP parser reports warning

Example

<?php
$fp=fopen("nosuchfile.txt","r");
echo "Hello World \n";
?>

Output

Following result will be displayed

Hello World
PHP Warning: fopen(nosuchfile.txt): failed to open stream: No such file or directory in /home/cg/root/1569997/main.php on line 2

Prepending @ symbol to fopen() expression suppresses error message and statement itself is ignored

Example

<?php
$fp=@fopen("nosuchfile.txt","r");
echo "Hello World";
?>

Output

Following result will be displayed

Hello World