2013-05-13 96 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通常是一個壞主意。

相關問題