What is unexpected T_VARIABLE in PHP?

笑着哭i 提交于 2019-11-26 12:24:41

问题


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?


回答1:


There might be a semicolon or bracket missing a line before your pasted line. It seems fine to me, every string is allowed as array index.




回答2:


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".




回答3:


It my case it was issue of PHP version.

.phar file I was using was not compatible with PHP 5.3.9. Switching interpreter to PHP 7 did fix it.



来源:https://stackoverflow.com/questions/1464919/what-is-unexpected-t-variable-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!