语法错误,eval()代码中出现意外的"=" [英] syntax error, unexpected '=' in eval()'d code

查看:82
本文介绍了语法错误,eval()代码中出现意外的"="的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码有什么问题:

<?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()代码中出现意外的"="的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆