Eval() in PHP7

Can anyone help me with getting eval() to work in php7

$A = 1;
$B = 2;
$C = '';
eval($A + $B);

gives
Parse error : syntax error, unexpected end of file in C:\xampp\htdocs… : eval()'d code on line 1

I have tired

eval($C = $A + $B);
eval("$C = $A + $B");

and added various semicolons. It was working on PHP5 but now on PHP 7 I cant get it to work.

BTW, please do not give me a lecture about the dangers of eval(). thans in advance.

Since nothing you posted works in php5 either, I recommend that you read the php.net documentation for eval() to make sure you are supplying it with an expected input parameter.

The only php7 change that would affect how this would work has to do with indirect access to variables, properties, and methods, of which the posted code has none.

Sponsor our Newsletter | Privacy Policy | Terms of Service