Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm having a problem with this... it says "unexpected T_VARIABLE". The problematic line is this:

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

I tried removing the $ (in $children), but it still results in error. It says "Parse error: syntax error, unexpected '[' in ..."

Oddly, this works without problem in PHP 5.2. But in PHP 5.3, the problem appears.

Since I'm not really a programmer (only know a little basic, I mostly design), I'm really clueless with what's going on here. Could anyone provide a help?

Here is the complete function:

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;

}
share|improve this question

4 Answers

up vote 1 down vote accepted

You're looking in the wrong place.

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

It should be $children, not \$children.


As for why this worked in PHP 5.2 and not in PHP 5.3, the '\' character was introduced for namespaces (e.g. MyNamespace\SubSpace\Something).

Given the following code:

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

In PHP 5.2, the result will be like:

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

Hello world

In PHP 5.3:

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

In PHP 5.4:

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

share|improve this answer
Thanks a lot! Works like a charm. I presume that removing the '\' would prevent error for PHP 5.4 too? – deathlock Mar 11 '12 at 14:11

Try this. I've rewritten the whole line to be a bit clearer (and more conformative).

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

Also change line 1270 from your pastebin to:

$the_html = str_replace('</option><!--fx:'.$idx.'-->', '(+'.count($children[$idx]).' '.$ibforums->lang['fj_subforums'].')</option>', $the_html);
share|improve this answer
Still results in the same error... Sorry I forgot to mention that the code I posted above works in PHP 5.2, but in PHP 5.3 it's broken. Not sure why... – deathlock Mar 9 '12 at 9:10
There are two very similar lines to the one you pasted, are you sure you're updating the correct one? – deed02392 Mar 9 '12 at 10:29
Yes, I'm updating with your code. It still results the same error. – deathlock Mar 9 '12 at 11:14
Works in 5.2 and 5.3 for me. You need to recheck. – deed02392 Mar 9 '12 at 12:05
I have rechecked it thousand times, even created two different files just to make sure (so I could compare it with Notepad++). But still, both don't work. Same error. To be precise, it doesn't work with PHP 5.3.8. It says: Parse error: syntax error, unexpected T_VARIABLE, expecting T_STRING in X:\xampp\htdocs\forum\sources\functions.php on line 1277 – deathlock Mar 11 '12 at 4:56
show 3 more comments

http://wordpress.org/support/topic/plugin-post-google-map-coud-not-to-activate-the-plugin

I got this same error, after WP was working, but PHP was updated, from the following code:

if($bgc==""){
    $bgc="#eeeeee";
}else{ \
    $bgc="";
}
$gmp_action = "delete-address";
?>

Removing the backslash fixed it.

share|improve this answer

Try this:

$children[ $i['parent_id'] ][] = array($i['forum_id'], '<option value="'.$i['forum_id'].'"'.$sub_css.'"'.$selected.'>  ', $i['forum_name'].$is_sub.'</option>'."\n");
share|improve this answer
Still results in the same error... – deathlock Mar 9 '12 at 9:07
Sorry I forgot to mention that the code I posted above works in PHP 5.2, but in PHP 5.3 it's broken. Not sure why... – deathlock Mar 9 '12 at 9:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.