What is unexpected T_VARIABLE in PHP?

后端 未结 3 2051
悲&欢浪女
悲&欢浪女 2020-12-04 15:13

I get this PHP error:

Parse error: syntax error, unexpected T_VARIABLE

From this line:

$list[$i][$docinfo[\'at         


        
3条回答
  •  不思量自难忘°
    2020-12-04 15:30

    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:

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

提交回复
热议问题