2013-05-13 98 views
-1

我收到错误未定义函数。PHP错误未定义函数

下面是代码:

$myvar = "@file_get_contents"; 

eval($myvar("http://someurlupdatehere.com")); 

The error I get is: 

<b>Fatal error</b>: Call to undefined function @file_get_contents() .. 
+3

删除错误控制运算符lol – 2013-05-13 20:17:03

回答

1

它看起来很奇怪对我有什么你正在尝试做的。我倾向于说:“不要使用eval,不要那样做!” ;)

反正,来了正确的语法:

$myvar = "@file_get_contents"; 
eval("$myvar('http://someurlupdatehere.com');"); 

或者,如果你需要在一个变量的file_get_contents()返回值(什么是可能的,使用此:

$myvar = "@file_get_contents"; 
eval("\$file = $myvar('http://someurlupdatehere.com');"); 
echo $file; 
+2

正确的语法是'file_get_contents('http://someurlupdatehere.com');',no eval – 2013-05-13 20:25:41

+0

@OneTrickPony你怎么能这样说,不知道OP在做什么?不喜欢这样的表述。 – hek2mgl 2013-05-13 20:47:22

+0

如果OP正在尝试做这个问题提出的其他问题,他应该相应地更新Q.否则我的声明仍然有效 – 2013-05-13 21:17:29

0
<?php 
$myvar = "file_get_contents"; 

eval(@$myvar("http://someurlupdatehere.com")); 
?> 

同样适用。抑制错误。

3

@file_get_contents()不是一个有效的PHP函数。已经抑制操作,使这项工作:

$myvar = "file_get_contents"; 

如果您仍然需要使用抑制操作,这样做:

eval('@' . $myvar("http://someurlupdatehere.com")); 

甚至离开抑制经营者和传递整个行的字符串:

$myvar = "@file_get_contents"; 
eval("$myvar('http://someurlupdatehere.com');"); 

请注意,使用抑制运算符和eval通常是一个坏主意。

相关问题