简体   繁体   English

php中的@readfile?

[英]@readfile in php?

I hate that google can not search for symbols. 我讨厌google无法搜索符号。 I saw this in some sample code and wondered why there is an @ sign before the readfile function: 我在一些示例代码中看到了这一点,并想知道为什么在readfile函数之前有@符号:

@readfile($filename);

What does it mean different to without an @ symbol? 没有@符号意味着什么不同?

An @ before a command in PHP means that no errors are printed. PHP中的命令之前的@表示不打印任何错误。 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; 如果你删除了@readfile会遇到错误(例如无法读取文件),那么 - 根据你的PHP设置 - 错误信息将在你的网站内容中; 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.) (如果在调用header()start_session()之前发生这种情况会变得更糟,因为一旦发送了内容,就不start_session()写入标题了。)

我将@称为“stfu运算符”。

It is PHP's error suppression operator. 它是PHP的错误抑制运算符。 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 由于@操作是很慢的,它不会在工作ini_set例如@ini_set在PHP如PHP6的未来版本

Important Reading: 重要阅读:

Bad uses of the @ operator @运算符的错误用法

It's error control operator . 它是错误控制操作员 Manual will tell you everything... 手册会告诉你一切......

@表示“不显示错误/警告”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM