I have things like this using eval()
:
$result = eval("return ".$value1.$operator.$value2.";");
Where the operator is from a variable, or a db field.
How would I go about achieving the same result without using eval
? Is it possible?
It's not a security concern as the values/operator aren't user entered, but it may be a performance concern if this comment at the PHP manual is anything to go by. Plus, if at some point I want to try out Facebook's HipHop I need to replace all uses of eval
with something else.