I'd like to use php eval() to identify potential parse errors. I'm aware of the dangers of eval, but this is a very limited use which will be fully validated beforehand.
I believe that in php 7 we should be able to catch a parse error, but it doesn't work. Here's an example:
$one = "hello";
$two = " world";
$three = '';
$cmdstr = '$three = $one . $tw;';
try {
$result = eval($cmdstr);
} catch (ParseError $e) {
echo 'error: ' . $e;
}
echo $three;
I'm trying to cause a parse error here to see if I can catch it, but when I run it, the error (undefined variable tw) appears as it usually would. It was not being caught.
Any ideas how to catch a parse error from eval?
=-$three $one . $tw;