fopen() 错误处理
我目前正在编写一个脚本,该脚本读取 HTML
模板文件,用数据填充它,然后将填充的 HTML
文件保存为缓存中的缓存副本文件夹。
当运行时错误被抑制时,我在评估 fopen()
是否发生错误时遇到了真正的困难:
$file = @fopen($location,"w+");
// manual states fopen() returns false on error
// though the below does not catch any errors
if (!$file) {
$this->doSomething();
}
这种抑制对我不利吗?我真的很感激对此有一些见解。我尝试将 error_reporting
设置为不显示错误,
ini_set('display_errors',0);
ini_set('log_errors',1);
error_reporting(E_ALL);
并删除了 fopen()
的抑制,但无济于事。
I'm working on a script at the moment that reads in an HTML
template file, populates it with data and then saves the populated HTML
file as a cached copy in my cache folder.
I'm having real difficulties evaluating whether an error has occured with fopen()
while runtime errors are suppressed:
$file = @fopen($location,"w+");
// manual states fopen() returns false on error
// though the below does not catch any errors
if (!$file) {
$this->doSomething();
}
Is the suppression working against me? I would really appreciate some insight into this. I have tried setting error_reporting
to display no errors,
ini_set('display_errors',0);
ini_set('log_errors',1);
error_reporting(E_ALL);
and removed the supression from fopen()
but to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码应该可以工作。如果您从未输入
if
语句并且没有触发任何错误,则文件已成功打开。为什么您确定fopen()
调用失败?You code should work. If you never enter the
if
statement and no errors are triggered, the file was opened successfully. Why are you sure that thefopen()
call failed?