Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is unexpected T_VARIABLE in PHP?

I get this PHP error:

Parse error: syntax error, unexpected T_VARIABLE

From this line:

$list[$i][$docinfo['attrs']['@groupby']] = $docinfo['attrs']['@count']; 

Is there anything wrong with this line?

like image 632
omg Avatar asked Sep 23 '09 09:09

omg


People also ask

What is unexpected end of file in PHP?

About Unexpected End of File Errors The “unexpected end of file” error is not specific to WordPress, and can happen on any PHP-based website. This specific error means the file mentioned in the error message ends abruptly without the proper closing tags, and the code was unable to be parsed as a result.

How can solve parse error syntax error unexpected in PHP?

To solve the missing parenthesis error in PHP, the code has to be checked from the beginning to search for it. One way to avoid errors is to use proper indentation in the code. Once all the parentheses in the code have been set correctly, parse error: syntax error, unexpected $end will be fixed.


2 Answers

There might be a semicolon or bracket missing a line before your pasted line.

It seems fine to me; every string is allowed as an array index.

like image 119
knittl Avatar answered Oct 14 '22 05:10

knittl


It could be some other line as well. PHP is not always that exact.

Probably you are just missing a semicolon on previous line.

How to reproduce this error, put this in a file called a.php:

<?php   $a = 5   $b = 7;        // Error happens here.   print $b; ?> 

Run it:

eric@dev ~ $ php a.php  PHP Parse error:  syntax error, unexpected T_VARIABLE in /home/el/code/a.php on line 3 

Explanation:

The PHP parser converts your program to a series of tokens. A T_VARIABLE is a Token of type VARIABLE. When the parser processes tokens, it tries to make sense of them, and throws errors if it receives a variable where none is allowed.

In the simple case above with variable $b, the parser tried to process this:

$a = 5 $b = 7; 

The PHP parser looks at the $b after the 5 and says "that is unexpected".

like image 27
dusoft Avatar answered Oct 14 '22 06:10

dusoft