eval php
The PHP eval () construct is used to evaluate an input string as PHP and then process it as such. Eval() is not a function, but it works like one in the sense that it outputs everything—except instead of outputting it as text, it outputs it as PHP code to be executed. One use of the eval() construct is to store code in a database to execute later.
PHP eval()构造用于将输入字符串评估为PHP,然后以这种方式对其进行处理。 Eval()不是函数,但是就其功能而言,它就像输出一个东西一样工作-除了将其输出为文本而不是将其输出为要执行PHP代码之外,它的功能与之类似。 eval()构造的一种用法是将代码存储在数据库中,以便以后执行。
Eval()语言构造的示例 ( Example of Eval() Language Construct )
Here is a simple example of coding for the eval() language construct.
这是对eval()语言构造进行编码的简单示例。
";
eval("\$a = \"$a\";");
print $a . "
";
?>
This code example outputs My friends are $name and $name2 when first called with the print statement, and it outputs My friends are Joe and Jim when called the second time after running eval ().
此代码示例在第一次使用print语句调用时,输出My friends是$ name和$ name2 ,在运行eval()之后第二次调用时,输出My Friends是Joe和Jim 。
Eval()的要求和特征 ( Requirements and Characteristics of Eval() )
- The passed code can't be wrapped in opening and closing PHP tags. 传递的代码不能包装在打开和关闭PHP标签中。
- The passed code must be valid PHP. 传递的代码必须是有效PHP。
- All statements must be terminated with a semicolon. 所有语句必须以分号终止。
A return statement terminates the code evaluation.
return语句终止代码评估。
- Any variable defined or changed in eval() remains after it terminates. eval()中定义或更改的任何变量在终止后都会保留。
- What a fatal error occurs in the evaluated code, the script exits. 如果在评估的代码中发生致命错误,脚本将退出。
- Because eval() is a language construct and not a function, it can't be used in higher-order functions. 由于eval()是语言构造而不是函数,因此不能在高阶函数中使用。
使用Eval()的危险 ( The Danger of Using Eval() )
The PHP manual discourages the use of the eval() construct, stressing its use is "very dangerous" because arbitrary PHP code can be executed. Users are instructed to use any other option than eval() unless that is not possible. The use of PHP eval() construct presents security risks.
PHP手册不鼓励使用eval()构造,强调使用它“非常危险”,因为可以执行任意PHP代码。 指示用户使用eval()以外的任何其他选项,除非不可能。 PHP eval()构造的使用存在安全风险。
eval php