Reputation: 150
This is my code:
$val1 = 0; $val2 = 3; $cond = '>';
$check = $val1.$cond.$val2;
echo eval('return $check;') ? 'true' : 'false';
I have a function that, using received parameters, is generating dynamic if statements.
All the statements are generated without errors.
The above code is an example of the code used in said function.
The problem is that all statements return TRUE.
I am sure that I am using eval in a wrong way, but I cannot figure out how.
Upvotes: 0
Views: 59
Reputation: 31173
If you use single quotes the text is interpreted as is, which means you are evaluating return $check
. You want to use double quotes which means you're evaluating return 0>3
.
So use echo eval("return $check;") ? 'true' : 'false';
.
Upvotes: 1