如何输出PHP文件打开失败的原因
我正在尝试调试一个巨大的、过时的(大约 2001 年)PHP Web 服务,但遇到文件打开失败的情况。 fopen 调用位于包含的模块中,调用者正在记录文件无法打开,但没有记录任何原因。
实际执行打开操作的代码是:
// Read the file
if (!($fp = @fopen($fileName, 'rb'))) {
$errStr = "Failed to open '{$fileName}' for read.";
break; // try-block
}
How can I find why fopen failed?
I'm trying to debug a huge, antiquated (circa 2001) PHP web service and I'm encountering file open failures. The fopen call is in an included module, the caller is logging that the file could not be opened but no reason is being logged.
The code that actually does the open is:
// Read the file
if (!($fp = @fopen($fileName, 'rb'))) {
$errStr = "Failed to open '{$fileName}' for read.";
break; // try-block
}
How can I find out why fopen failed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除错误抑制器。
Remove the error suppressor.
关于 @ 运算符,已经给出了很好的答案,但这里是更多信息可能对您或其他人有用:
@ 运算符
,您可以安装 scream 扩展 -- 另请参阅 手册 -- 当您维护某种设计/编码不佳的旧应用程序时,这非常有用 ^^track_errors
选项已激活),您也许可以使用$ php_errormsg
获取最后一条错误消息。考虑这段代码:
你会得到这样的:
所以,真实的,有用的,有意义的错误消息;-)
Great answers have already been given, about the @ operator, but here's a couple of more informations that could be useful, either to you or someone else :
@ operator
, you can install the scream extension -- see also the manual -- which is really useful when you're maintaining some kind of old application not well designed / coded ^^track_errors
option is activated), you might be able to use$php_errormsg
to get the last error message.Considering this piece of code :
You would get this :
So, real, useful, meaningful, error messages ;-)
去掉@符号。
@ 符号抑制错误消息,因此它抑制了函数通常会给出的错误。
Take away the @ sign.
The @ sign suppresses error messages, so it is supressing the error the the function would normally give.