2012-09-18 65 views
1

我得到這個錯誤:需要幫助診斷:解析錯誤:語法錯誤,意想不到的T_FUNCTION

Parse error: syntax error, unexpected T_FUNCTION

這段代碼:

<?php 
    $uniqueFtypes = $ftypes = $converter->GetConvertedFileTypes(); 
    array_walk(
     $uniqueFtypes, 
     function(&$ftype, $key) { 
      $ftype = $ftype['fileExt']; 
     } 
    ); 
    $uniqueFtypes = array_values(array_unique($uniqueFtypes)); 
    foreach ($uniqueFtypes as $key => $uftype) 
    { 
     echo $uftype; 
     echo ($uftype != end($uniqueFtypes)) ? (($key != count($uniqueFtypes)-2) ? ', ' : ', or ') : ''; 
    } 
?> 

在這一行:

array_walk(
    $uniqueFtypes, 
    function(&$ftype, $key) { 
     $ftype = $ftype['fileExt']; 
    } 
); 

PHP版本:5.2.17

它在localhost上運行,我正在使用最新的UniServer。但是當我將它移到我的主機時,它會發生這種錯誤。

任何幫助? :)

編輯:這裏是其他人不知道它需要修復。

ini_set('max_execution_time',0); 
ini_set('display_errors',0); 

// Instantiate converter class 
include 'VideoConverter.class.php'; 
$converter = new VideoConverter(); 

// On download of converted file 
if (isset($_GET['output'])) 
{ 
    $converter->DownloadConvertedFile($_GET['output']); 
} 

$vidHosts = array_values($converter->GetVideoHosts()); 
    foreach ($vidHosts as $key => $host) 
    { 
     echo $host['name']; 
     echo ($host != end($vidHosts)) ? (($key == count($vidHosts)-2) ? ((count($vidHosts) > 2) ? ', and ' : ' and ') : ', ') : ''; 
    } 

有什麼需要這2也固定?

+0

您是否確認本地主機和遠程主機上的PHP版本相同? – Sepster

回答

6

你不能在php 5.3之前使用閉包。您需要在array_walk的第二個參數中將function更改爲create_function。請嘗試:

array_walk($uniqueFtypes, create_function('&$ftype, $key;', 
    '$ftype = $ftype["fileExt"];')); 
+0

感謝您的回覆,在更改該行後,它僅在我的頁面上顯示爲白色,因此我認爲還有其他代碼需要修復。我編輯了第一篇文章,以顯示可能需要修復的其他代碼,你能否告訴它是否如此? – Lanibox

+0

@Lanibox它不僅應該顯示白色;打開錯誤並告訴我他們是什麼,所以我可以幫助你。但是,如果您有多個不同的問題,我認爲您應該接受並創建一個單獨的問題。 –

相關問題