When I was using scandir
to scan some specific dir without system permission, I got this output from my php:
<br />
<b>Warning</b>: scandir(/root): failed to open dir: Permission denied in <b>/var/blog/wordpress/ask.php</b> on line <b>17</b><br />
<br />
<b>Warning</b>: scandir(): (errno 13): Permission denied in <b>/var/blog/wordpress/ask.php</b> on line <b>17</b><br />
I don't know why there were 2 similar warning output from php.(I guessed that one is php's and the other is shell's ? Plz tell me.)
I tried to capture this warning(capture the linux errno) to notify my browser client to retype a dir with fully permission.
My code is just like this:
set_error_handler("warning_handler");
scandir ("/root");
restore_error_handler();
// this $errno is not scandir's $errno (Linux $errno)
function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext) {
// error was suppressed with the @-operator
if (0 === error_reporting()) {
return false;
}
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
But only one warning would be captured(the one without string'errno'). So now I am wondering if there is a method to capture all warnings? Or any other hack methods?
I don't mean that I need a way to try……catch a warning. But there are some situations that I can't fully catch warnings using the method of that.