关于eval的用法

记得06年的时候,刘杰吵着php5里有eval,用着很爽,今天终于用到了,很好很强大。
用法:
class testclass{
function test($a,$b) {
echo $a;
}

}
$p = “1,2″;
$testclass = new testclass();
eval(“\$testclass->test($p);”);
最终结果输出了1,如果在$p前加转义\,那么输出结果为1,2

Comments (5)

极品家丁二月 27th, 2010 at 06:00

顶一下,
如果在$p前加转义\,那么输出结果为1,2
加\是什么情况呢
eval(”\$testclass->test($p);”);

eval(”\$testclass->test(1,2);”);
有区别吗

极品家丁二月 27th, 2010 at 06:02

豪哥,你的网站留言时间有问题吧,是用时间戳写的吧,跟现在时机时间差14个小时啊,是时区问题吗?

极品家丁二月 27th, 2010 at 06:02

我现在的实际时间是晚上22点啊

admin二月 28th, 2010 at 17:09

转义之后才能执行类函数,否则执行不了的。
第二个问题,区别没有,但是如果想把1、2当成一个变量,而且不定长,那么这样写就很有用了。

啊龙三月 7th, 2010 at 06:52

博客蛮个性的,路过了,帮你踩一下。

Leave a comment

Your comment