开发者

@readfile in php?

开发者 https://www.devze.com 2022-12-27 17:18 出处:网络
I hate that google can not search for symbol开发者_C百科s. I saw this in some sample code and wondered why there is an @ sign before the readfile function:

I hate that google can not search for symbol开发者_C百科s. 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?


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.)


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


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


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


@ means "don't show errors/warnings"


FYI

You can use " " to search queries containing special characters in google.

Example to search - @readfile in PHP? search it

You can search - "@readfile in PHP?" search it

0

精彩评论

暂无评论...
验证码 换一张
取 消