Asif Iqbal Asif Iqbal - 7 months ago 37
PHP Question

Is there any way to catch fatal error using eval()?

$code = 'php statement';

// getting perse error
function perse_error_check($code){
if(eval($code) === "true"){
return "no perse error";
}

if(eval($code) === "false"){
return "perse error found";
}
}


// getting fatal error
function fatal_error_check($code){
.......................................
.......................................
}


Can you help me to complete the second function? Actually I am not sure weather it is possible or not.

Answer

There is a simple way. Put your PHP code in an another file. For an example: index.php and check.php . Put your PHP code in check.php.

Now in index.php write:

$check_data = file_get_contents("yourhosturl/allotherdirectory/check.php");

if(preg_match("/Fatal error/",$check_data)){
    echo "fatal error found"; 
}
Comments