Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@readfile in php?

Tags:

php

readfile

I hate that google can not search for symbols. I saw this in some sample code and wondered why there is an @ sign before the readfile function:

@readfile($filename);

What does it mean different to without an @ symbol?

like image 519
Jonathan. Avatar asked Apr 16 '10 16:04

Jonathan.


4 Answers

An @ before a command in PHP means that no errors are printed. It's called the error control operator.

If you removed the @ and readfile would encounter an error (such as not being able to read the file), then—depending on your PHP settings—the error message will be amidst your site content; something you rarely, if ever, want. (It gets worse even, if this happens before a call to header() or start_session() because once content is sent, the headers can't be written anymore.)

like image 113
Joey Avatar answered Nov 02 '22 17:11

Joey


I refer to @ as being the "stfu operator".

like image 31
goat Avatar answered Nov 02 '22 15:11

goat


It is PHP's error suppression operator. With it you can suppress error messages.

Tip:

Simply don’t use the error suppression operator with speed-critical code.

Future:

Because @ operator is very slow, it won't work on ini_set eg @ini_set in future version of PHP eg PHP6

Important Reading:

Bad uses of the @ operator

like image 42
Sarfraz Avatar answered Nov 02 '22 16:11

Sarfraz


It's error control operator. Manual will tell you everything...

like image 5
Crozin Avatar answered Nov 02 '22 15:11

Crozin