PHP script stops processing warning error?

I have a PHP script that stops processing (seemingly) a PHP warning. The error is a general "PHP Warning: fopen" - "could not open the stream: there is no such file or directory."

Should PHP stop here? I only thought about fatal errors?

Is there any way to make it continue?

+3
source share
6 answers

I don’t know how to continue errors, but it is best to prevent errors in the first place:

http://php.net/manual/en/function.file-exists.php

http://www.php.net/manual/en/function.is-readable.php

+2
source

, script . , script , , , .

file_exists is_readable .

+2

, , error_reporting() .

, . "@" fopen, waring, : @fopen(...)

+1

php,

, E_WARNING. @ .

+1
source

In addition to what Conrad Mayer mentioned in the PHP manual:

$fres = @fopen('file.ext','w+');
if($fres){
  // so anything you want with the file
}

fopenreturns false on error. When an error is suppressed on fopen and you are not using it if($fres), subsequent file functions will cause an error, saying that $fresit is not a valid file descriptor.

0
source

Even if this continues, the program will most likely not work as it was intended. Anyway, try to handle the exception:

try {
    # code that may cause an error
}
catch( Exception $e ) {
    # do error handling mechanism
}
-1
source

Source: https://habr.com/ru/post/1723982/


All Articles