1

Im executing the list of php codes via eval, If there is any error in code i want to display this code have fatal error/parse error.

is there any way to give custom message for fatal error or any other error

My code is like this :

$output = []; foreach($codes as $key => $res) { if(eval($res['code'])) { eval($res['code']); $output[$key] = $result; } else { $output[$key] = "Fatal error in code"; } } var_dump($output); 
1

2 Answers 2

1

There is a way! Write the code to a file, using php -l in the eval, then delete the file. See my answer for example code:

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

Sign up to request clarification or add additional context in comments.

Comments

1

The trick is to expect Throwable:

try { ... @eval(...); ... } catch(Throwable $t) { ... } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.