PHP eval $ a ="$ a"? [英] PHP eval $a="$a"?

查看:87
本文介绍了PHP eval $ a ="$ a"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一些工作代码,并发现以下内容:

I was looking through some code for work, and came across this line:

eval("\$element = \"$element\";");

对于为什么任何PHP开发人员都会编写此行,我确实感到困惑.除了为其本身设置变量外,这还可以达到什么目的?

I'm really confused as to why any PHP developer would've written this line. What purpose does this serve, besides setting a variable to itself?

幸运的是,此行所在的函数从未调用过.

Luckily, the function this line is in is never called.

推荐答案

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

上面的示例将输出:

This is a $string with my $name in it.
This is a cup with my coffee in it.

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

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

I do just ctl+c ctrl+v :-)

这篇关于PHP eval $ a ="$ a"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆