Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fopen() error handling

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.

like image 410
David Barker Avatar asked Oct 09 '22 16:10

David Barker


1 Answers

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 the fopen() call failed?

like image 54
DaveRandom Avatar answered Oct 24 '22 03:10

DaveRandom