问题描述
此代码有什么问题:
<?php eval(" $start = microtime(true)*1000; echo 'hello'; $end=microtime(true)*1000; $time = $end-$start; $time = round($time,4); echo '<br />Time taken: '.$time.'ms<br />'; "); ?>
这只是一个行代码(不要问为什么),但为了便于阅读,我重复
It's exactly one line code(dont ask why) but for readablility I repeat
<?php
eval(" $start = microtime(true)*1000;
echo 'hello';
$end=microtime(true)*1000;
$time = $end-$start;
$time = round($time,4);
echo '<br />Time taken: '.$time.'ms<br />';
");
?>
我收到此错误:Parse error: syntax error, unexpected '=' in ...\test2.php(1) : eval()'d code on line 1
I get this error: Parse error: syntax error, unexpected '=' in ...\test2.php(1) : eval()'d code on line 1
推荐答案
使用双引号时,您必须转义每个美元符号,如果没有美元符号,php将尝试将作用域中的变量解析为最终字符串.
When using double quotes, you have to escape every dollar sign, without it, php will try to resolve variables from your scope into the final string.
由于您可能未定义$start
变量,因此将其视为空字符串,并且代码以'='开头.
Since you probably don't have $start
variable defined, it is treated as empty string and your code starts with '='.
这篇关于语法错误,eval()代码中出现意外的"="的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!