I was been doing a php testing which uses eval() function, but it seems that eval() can't call user defined functions properly.
Please see my example:
function equals($a,$b){
if ($t == $r){
return true;
}
else{
throw new Exception("expected:<".$r."> but was:<".$t.">");
}
}
eval("$test = 1;");
try{
echo eval("equals($test,1);");
}
catch (Exception $e) {
echo $e->getMessage();
}
but what I have received is always like "expected:<1> but was:<>", but if I have do an
echo $test;
I can get 1.
I have tried changing $ to \$ by following the PHP eval() Manual, but it seems to break the eval function. (http://php.net/manual/en/function.eval.php)
So I am a bit of stack now, can someone help me with the problem. Thank you very much.