Reputation: 33238
What is wrong with this code:
<?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 />';
");
?>
I get this error:
Parse error: syntax error, unexpected '=' in ...\test2.php(1) : eval()'d code on line 1
Upvotes: 1
Views: 16969
Reputation: 29462
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.
Since you probably don't have $start
variable defined, it is treated as empty string and your code starts with '='.
Upvotes: 10
Reputation: 7795
Try this:
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 />\';
');
Upvotes: 0