Alternative to error_get_last ()

I am trying to debug a php script that runs on my university server. The current version of php is installed 5.1.6.

As far as I understand, error_get_last() will work only for versions >= 5.2 . I am trying to echo an error code for a failed call to mkdir() , which, I am sure, is caused by the permissions of one of the specified directories. I hope the error message will shed some light on this issue, but I cannot find a way to view the details of the error, and I do not think that I can even access other php error logs to check them there.

What are my other options?

+4
source share
2 answers

You can try to make your own error handler:

 # temporary error handler function tempErrorHandler($errNo, $errStr, $errFile, $errLine, array $errContext) { # continue to practice @ suppression if (0 === error_reporting()) { return false; } # throw it throw new ErrorException($errStr, 0, $errNo, $errFile, $errLine); } # make this the error handler for now.. set_error_handler('tempErrorHandler'); # use a try..catch try { mkdir('../directory with some permission problem../../'); } catch (ErrorException $e) { # echo it out echo $e->getMessage(); # or do whatever you want with it: this part is just an EXAMPLE $errMsg = $e->getMessage(); $isPermissionDenied = strpos($errMsg, 'Permission denied'); if ($isPermissionDenied) { # do something } } # revert to previous error handler restore_error_handler(); 

Pay attention to the comment # or do whatever you want with it: this part is just an EXAMPLE - I'm not sure what error you will get in version 5.1.6 , so you can just play with it.

+1
source

It looks like you can access the error message as part of the error back in php4 using the reserved variable $ php_errormsg. if you are not using a custom error message handler (see http://php.net/manual/en/reserved.variables.phperrormsg.php ) for more details.

0
source

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


All Articles