I'm very new to PHP. I have a line of code on a server side script that opens a file:
$fh = fopen($myFile, 'r');
When I run this code through phplint, it gives me the notice:
$fh = fopen($myFile, 'r'); \_ HERE ==== 19: notice: unhandled error(s): E_WARNING
I tried creating an error handler earlier and specifically setting it to handle
E_WARNING like this:
But I get the same notice. I'd like to do this correctly. Is there some other mechanism to handle this error that
phplint thinks is correct?
The PHPLint warning indicates that the function (fopen in this case) is documented as "raising" an E_WARNING if an error condition occurs.
If this occurs, then odds are that you will get an error message displayed in the console or on screen. Most programmers don't want this in production code and will silence the error by adding @ to suppress this warning or changing the php.ini (error_reporting).
PHPLint is just reminding you that you did not add the @. Lint would like your code to be more like:
$fh = @fopen($myFile, 'r'); // check $fh here
Obviously adding a file_exists() or is_readable() before the call would not silence PHPLint.
Ref: http://php.net/manual/en/function.fopen.php "If the open fails, an error of level E_WARNING is generated. You may use @ to suppress this warning."