php - 未定义函数 eval() - PHP

标签 php

我正在尝试像那样使用 eval() 函数:

$foo = 'eval';
$bar = 'echo 1;';
$foo($bar);

但我收到一个错误: fatal error :调用未定义的函数 eval()

这很奇怪,因为下面的代码是有效的

$foo = 'base64_encode';
$bar = 'foobar';
echo $foo($bar);

有人可以帮忙吗?

最佳答案

来自eval documentation :

Note: Because this is a language construct and not a function, it cannot be called using variable functions.

点击注释中的链接,您还将找到:

Variable functions won't work with language constructs such as echo, print, unset(), isset(), empty(), include, require and the like. Utilize wrapper functions to make use of any of these constructs as variable functions.

关于php - 未定义函数 eval() - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29707896/

相关文章:

java - mcrypt "ncfb"模式的 Java 等价物是什么?

javascript - 将 Javascript 变量作为图像传递给 PHP

PHP htaccess 将查询字符串从大写重定向到小写

javascript - 脚本和 css 未加载到 Web 服务器中

php - openshift DB 配置导致 503

php - mysql通过php脚本加载数据infile - 不工作

php - 在 MySQL 中使用许多 bool 列是否比结合 PHP 的较长字符串更快?

php - 如何在(时间),在 laravel 4 中发布

php - PHP日期功能不起作用

php - DomPDF 在本地而不是在线加载字体