how to handle parse error for eval function in php

Solution:

From the manual

As of PHP 7, if there is a parse error in the evaluated code, eval() throws a ParseError exception. Before PHP 7, in this case eval() returned FALSE and execution of the following code continued normally. It is not possible to catch a parse error in eval() using set_error_handler().

Instead use this:

<?php

try {
    eval('will cause error');
} catch (ParseError $e) {
    echo 'Caught exception: '.$e->getMessage()."\n";
}

https://3v4l.org/1giOS