0

For example if I have this PHP code

$template = 'A = {$a}, b = {$b}';
$a = "A";
$b = "B";

eval("\$output = \"".$template."\";");

echo $output;

The result would be A = A, b = B. But if I don't want eval() to parse the var $b (without using unset()), what should I do?

DavideR
  • 570
  • 4
  • 18
  • 5
    Either remove the variable from scope or remove the `{$b}` from `$template`. Those are basically the two choices in this situation. I'd rather question whether this is a good idea to begin with though. `eval` should be avoided at all costs. – deceze May 23 '14 at 15:42
  • 2
    This is really the wrong questions imho. The real question should have been: "how can I do whatever I am doing without the use of `eval`?" – PeeHaa May 23 '14 at 15:43

0 Answers0