PHP 中意外的 T_VARIABLE 是什么?
我收到这个 PHP 错误:
解析错误:语法错误,意外 T_VARIABLE
从这一行:
$list[$i][$docinfo['attrs']['@groupby']] = $docinfo['attrs']['@count'];
这一行有什么问题吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
粘贴的行之前可能缺少分号或括号。
对我来说这似乎很好;每个字符串都可以作为数组索引。
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.
也可能是其他线路。 PHP 并不总是那么精确。
可能您只是在上一行中缺少一个分号。
如何重现此错误,请将其放入名为
a.php
的文件中:运行它:
:
说明 PHP 解析器将您的程序转换为一系列标记。
T_VARIABLE
是 VARIABLE 类型的令牌。当解析器处理标记时,它会尝试理解它们,如果它接收到不允许的变量,则会抛出错误。在上面使用变量
$b
的简单情况中,解析器尝试处理此问题:PHP 解析器查看 5 之后的 $b 并说“这是意外的”。
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
:Run it:
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:The PHP parser looks at the $b after the 5 and says "that is unexpected".
就我而言,这是 PHP 版本的问题。
我使用的 .phar 文件与 PHP 5.3.9 不兼容。将解释器切换到 PHP 7 确实解决了这个问题。
In my case it was an issue of the PHP version.
The .phar file I was using was not compatible with PHP 5.3.9. Switching interpreter to PHP 7 did fix it.