2012-03-09 333 views
1

我遇到了這個問題......它說「意外的T_VARIABLE」。該問題的行是這樣的:解析錯誤:語法錯誤,意外的T_VARIABLE,期待PHP 5.3中的T_STRING

$children[ $i['parent_id'] ][] = array($i['forum_id'], "<option value=\"{$i['forum_id']}\"$selected>  ", "{$i['forum_name']}</option>\n");

我試着刪除$(在$children)的,但它仍然會導致錯誤。它說「解析錯誤:語法錯誤,意外'['in ...'

奇怪的是,這在PHP 5.2中沒有問題。但在PHP 5.3中,問題出現了。因爲我不是一個真正的程序員(只知道一點基本的東西,我主要是設計),但我對這裏發生的事情一無所知。任何人都可以提供幫助嗎?

下面是完整的功能:

function build_forum_jump($html=1, $override=0, $remove_redirects=0) 
{ 
    global $INFO, $DB, $ibforums; 
    $last_cat_id = -1; 

    if ($remove_redirects) 
    { 
     $qe = 'AND f.redirect_on <> 1'; 
    } 
    else 
    { 
     $qe = ''; 
    } 

    $DB->query("SELECT f.id as forum_id, f.parent_id, f.subwrap, f.sub_can_post, f.name as forum_name, f.position, f.redirect_on, f.read_perms, c.id as cat_id, c.name 
       FROM ibf_forums f 
       LEFT JOIN ibf_categories c ON (c.id=f.category) 
       WHERE c.state IN (1,2) $qe 
       ORDER BY c.position, f.position"); 


    if ($html == 1) { 

     $the_html = "<form onsubmit=\"if(document.jumpmenu.f.value == -1){return false;}\" action='{$ibforums->base_url}act=SF' method='get' name='jumpmenu'> 
        <input type='hidden' name='act' value='SF' />\n<input type='hidden' name='s' value='{$ibforums->session_id}' /> 
        <select name='f' onchange=\"if(this.options[this.selectedIndex].value != -1){ document.jumpmenu.submit() }\" class='forminput'> 
        <optgroup label=\"{$ibforums->lang['sj_title']}\"> 
         <option value='sj_home'>{$ibforums->lang['sj_home']}</option> 
         <option value='sj_search'>{$ibforums->lang['sj_search']}</option> 
         <option value='sj_help'>{$ibforums->lang['sj_help']}</option> 
        </optgroup> 
        <optgroup label=\"{$ibforums->lang['forum_jump']}\">"; 
    } 

    $forum_keys = array(); 
    $cat_keys = array(); 
    $children = array(); 
    $subs  = array(); 
    $subwrap = array(); 

    // disable short mode if we're compiling a mod form 

    if ($html == 0 or $override == 1) 
    { 
     $ibforums->vars['short_forum_jump'] = 0; 
    } 

    while ($i = $DB->fetch_row()) 
    { 
     $selected = ''; 
     $redirect = ""; 

     if ($html == 1 or $override == 1) 
     { 
      if ($ibforums->input['f'] and $ibforums->input['f'] == $i['forum_id']) 
      { 
       $selected = ' selected="selected"'; 
      } 
     } 

     if ($i['redirect_on']) 
     { 
      $redirect = $ibforums->lang['fj_redirect']; 
     } 

     if ($i['subwrap'] == 1) 
     { 
      $subwrap[ $i['forum_id'] ] = 1; 
     } 

     if ($i['subwrap'] == 1 and $i['sub_can_post'] != 1) 
     { 
     /*************************** 
     *** INFINITE SUBFORUMS 
     ****************************/ 
     if ($i['parent_id'] > 0) { 
      $children[ $i['parent_id'] ][] = array($i['forum_id'], "<option value=\"{$i['forum_id']}\"".$sub_css."$selected>  ", "{$i['forum_name']}$is_sub</option>\n"); 
     } 
     else { 
      $forum_keys[ $i['cat_id'] ][$i['forum_id']] = "<option value=\"{$i['forum_id']}\"".$sub_css."$selected>  -{$i['forum_name']}$is_sub</option>\n"; 
     } 
     /**********INFINITE - END**************/ 

     } 
     else 
     { 
      if ($this->check_perms($i['read_perms']) == TRUE) 
      { 
       if ($i['parent_id'] > 0) 
       { 
       /*************************** 
       *** INFINITE SUBFORUMS 
       ****************************/ 
       $children[ $i['parent_id'] ][] = array($i['forum_id'], "<option value=\"{$i['forum_id']}\"$selected>  ", "{$i['forum_name']}</option>\n"); 
       /**********INFINITE - END**************/ 
       } 
       else 
       { 
        $forum_keys[ $i['cat_id'] ][$i['forum_id']] = "<option value=\"{$i['forum_id']}\"".$selected.">&nbsp;&nbsp;- {$i['forum_name']} $redirect</option><!--fx:{$i['forum_id']}-->\n"; 
       } 
      } 
      else 
      { 
       continue; 
      } 
     } 

     if ($last_cat_id != $i['cat_id']) 
     { 

      // Make sure cats with hidden forums are not shown in forum jump 

      $cat_keys[ $i['cat_id'] ] = "<option value='-1'>{$i['name']}</option>\n"; 

      $last_cat_id = $i['cat_id']; 

     } 
    } 

    foreach($cat_keys as $cat_id => $cat_text) 
    { 
     if (is_array($forum_keys[$cat_id]) && count($forum_keys[$cat_id]) > 0) 
     { 
      $the_html .= $cat_text; 

      foreach($forum_keys[$cat_id] as $idx => $forum_text) 
      { 
       if ($subwrap[$idx] != 1) 
       { 
        $the_html .= $forum_text; 
       } 
       else if (count($children[$idx]) > 0) 
       { 
        $the_html .= $forum_text; 

        if ($ibforums->vars['short_forum_jump'] != 1) 
        { 
         /****** INFINITE SUBFORUMS FIX BEGINS ************/ 
         $the_html .= $this->subforums_addtoform($idx, \$children); 
         /********** INFINITE FIX - END ************/ 
        } 
        else 
        { 
         $the_html = str_replace("</option><!--fx:$idx-->", " (+".count($children[$idx])." {$ibforums->lang['fj_subforums']})</option>", $the_html); 
        } 
       } 
       else 
       { 
        $the_html .= $forum_text; 
       } 
      } 
     } 
    } 


    if ($html == 1) 
    { 
     $the_html .= "</optgroup>\n</select>&nbsp;<input type='submit' value='{$ibforums->lang['jmp_go']}' class='forminput' /></form>"; 
    } 

    return $the_html; 

} 

回答

1

你找錯了地方。

/****** INFINITE SUBFORUMS FIX BEGINS ************/ 
$the_html .= $this->subforums_addtoform($idx, \$children); 
/********** INFINITE FIX - END ************/ 

應該$children\$children


至於爲什麼這個工作在PHP 5.2,而不是在PHP 5.3中, '\' 字符被介紹爲namespaces(例如MyNamespace\SubSpace\Something)。

鑑於以下代碼:

function foo() { 
    $children = 'Hello world'; 
    echo \$children; 
} 
foo(); 

在PHP 5.2,其結果將是這樣的:

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in %s on line %d

Hello world

在PHP 5.3:

Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in %s on line %d

在PHP 5.4:

Parse error: syntax error, unexpected '$children' (T_VARIABLE), expecting identifier (T_STRING) in %s on line %d

+0

非常感謝!奇蹟般有效。我認爲刪除'\'也會防止PHP 5.4的錯誤? – deathlock 2012-03-11 14:11:33

1

試試這個。我已經改寫了整條線,使之更加清晰(並且更加符合規範)。

$children[$i['parent_id']][] = array($i['forum_id'], '<option value="'.$i['forum_id'].'"'.$selected.'> ', $i['forum_name'].'</option>\n'); 

而且從引擎收錄變線1270:

$the_html = str_replace('</option><!--fx:'.$idx.'-->', '(+'.count($children[$idx]).' '.$ibforums->lang['fj_subforums'].')</option>', $the_html); 
+0

仍然導致同樣的錯誤...抱歉,我忘了提及上面發佈的代碼在PHP 5.2中工作,但在PHP 5.3中它已經損壞。不知道爲什麼... – deathlock 2012-03-09 09:10:03

+0

您粘貼的線條有兩條非常相似的線條,您確定要更新正確的線條嗎? – deed02392 2012-03-09 10:29:50

+0

是的,我正在更新您的代碼。它仍然會導致相同的錯誤。 – deathlock 2012-03-09 11:14:40

0

試試這個:

$children[ $i['parent_id'] ][] = array($i['forum_id'], '<option value="'.$i['forum_id'].'"'.$sub_css.'"'.$selected.'> ', $i['forum_name'].$is_sub.'</option>'."\n"); 
+0

仍然導致相同的錯誤... – deathlock 2012-03-09 09:07:37

+0

對不起,我忘了提及的是,代碼我上面發佈的工作在PHP 5.2中,但在PHP 5.3中它已經損壞。不知道爲什麼... – deathlock 2012-03-09 09:09:53

相關問題