Hi Guys,
Is there anyway I can track parse errors? as for php.net help, it says we cannot use custom error handler for following errors,
The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of E_STRICT raised in the file where set_error_handler() is called.
But I will explain my situation so you guys can think of any alternative solution to overcome this problem.
My system has two ends where as from back-end admin will be entering all the formulas which will be used as a condition to display data on the front end (for users).
below is a sample formula,
//$open / $close / $openx values will be assign from the front end dynamically.
//This is only the formula.
//this will be stored in the database
($open > $close && ($close < ($openx-1)))
When ever front end user request for data the system will be assign $open / $close / $openx values dynamically and validate the values against the formula which was entered by the admin. here is how i`m doing it,
//assume i`m initializing values here
$open = 10; // getting from a database
$close = 20; // getting from a database
$openx = 30; // getting from a database
//this was fetched from the database
$formula = '($open > $close && ($close < ($openx-1)))';
eval("\$result = $formula;");
if($result)
{
//display all the matching data
}
else
{
//no records found display error
}
This works fine. but the problem arrives when ever admin enter a false formula. for example,
//this has an additional closing bracket
($open > $close && ($close < ($openx-1))))
This cause my system fail and it display lots of parse errors. 🙁
How can i prevent this? How can i check is there are any errors exists in the formula before PHP parser catches it?
Thanks in advance,
Regards,
niroshan