PHP eval $ a ="$ a"?

Roc*_*mat 7 php eval

我正在查看一些代码用于工作,并遇到了这一行:

eval("\$element = \"$element\";");
Run Code Online (Sandbox Code Playgroud)

我真的很困惑为什么任何PHP开发人员都会编写这一行.除了为自己设置变量之外,这还有什么用呢?

幸运的是,这条线的功能从未被调用过.

zod*_*zod 7

<?php
$string = 'cup';
$name = 'coffee';
$str = 'This is a $string with my $name in it.';
echo $str. "\n";
eval("\$str = \"$str\";");
echo $str. "\n";
?> 
Run Code Online (Sandbox Code Playgroud)

上面的例子将输出:

This is a $string with my $name in it.
This is a cup with my coffee in it.
Run Code Online (Sandbox Code Playgroud)

http://php.net/manual/en/function.eval.php

我只做ctl + c ctrl + v :-)