[英]php eval() error after updating
I cant seem to find the error in here, this code used to work then I updated PHP and now I get : 我似乎在这里找不到错误,这段代码曾经可以正常工作,然后我更新了PHP,现在得到了:
Parse error: syntax error, unexpected '10' (T_LNUMBER) in C:\\wamp\\www\\a\\1.php(15) : eval()'d code on line 1
解析错误:语法错误,C:\\ wamp \\ www \\ a \\ 1.php(15)中意外的'10'(T_LNUMBER),第1行上的eval()代码
$operande1 = 5;
$operande2 = 10;
$operation = "*";
calcul($operande1,$operande2,$operation);
function calcul($operande1, $operande2, $operation) {
echo $operande1;
echo $operande2;
echo $operation;
eval('$result=('.$operande1.")".$operation."(".$operande2.");");
}
Any help is appreciated 任何帮助表示赞赏
You're concatenating a string with a number in the eval. 您正在将字符串与评估中的数字连接起来。 Wrapping the
$operande1
inside strval($operande1)
should solve this. 将
$operande1
包装在strval($operande1)
应该可以解决此问题。 I don't recommend using eval at all but, it would look like this, another option is to simply have the numbers as strings, by initializing them inside quotation marks ie $operande1 = "10";
我完全不建议使用eval,但是,它看起来像这样,另一种选择是通过将数字初始化为引号,即
$operande1 = "10";
来简单地将数字作为字符串$operande1 = "10";
eval('$result=('.strval($operande1).")".$operation."(".strval($operande2).");");
Note that the eval
is just setting the value to the variable $result
, and you'll to do echo $result;
注意 ,
eval
只是将值设置为变量$result
,您将执行echo $result;
to print its value. 打印其值。
The only way I was able to reproduce the error that you posted 我能够重现您发布的错误的唯一方法
Parse error: syntax error, unexpected '10' (T_LNUMBER)
解析错误:语法错误,意外的'10'(T_LNUMBER)
was to leave out the =
sign. 将省略
=
符号。
$operande1 10;
which gave me 这给了我
Parse error: syntax error, unexpected '10' (T_LNUMBER)
解析错误:语法错误,意外的'10'(T_LNUMBER)
http://3v4l.org/o1vDg http://3v4l.org/o1vDg
Output for 5.4.0 - 5.6.2, php7@20140507 - 20141001 Parse error: syntax error, unexpected '10' (T_LNUMBER) in /in/o1vDg on line 3
5.4.0-5.6.2的输出,php7 @ 20140507-20141001解析错误:语法错误,行3的/ in / o1vDg中意外的'10'(T_LNUMBER)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.