eval php_Eval()PHP构造

PHP的eval()构造用于将字符串作为PHP代码执行,但存在安全隐患。它不是函数,但在执行时输出代码。eval()要求传递有效的PHP代码,且所有语句需以分号结束。代码中的变量在执行后仍保留。PHP手册警告其使用风险,建议避免在可能的情况下使用。
摘要由CSDN通过智能技术生成

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()构造的使用存在安全风险。

翻译自: https://www.thoughtco.com/eval-php-function-2694048

eval php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值