Parse error: Syntax error, unexpected end of file in my PHP code

后端 未结 16 2011
孤城傲影
孤城傲影 2020-11-22 05:27

I got an error:

Parse error: syntax error, unexpected end of file in the line

With this code:


    

        
16条回答
  •  清歌不尽
    2020-11-22 05:44

    Also, watch out for heredoc closing identifiers.

    Invalid Example:

    function findAll() {
        $query=<<

    This will throw an exception that resembles the following:


    Parse error: syntax error, unexpected end of file in [...][...] on line 5

    where number 5 might be the last line number of your file.

    According to php manual:

    Warning It is very important to note that the line with the closing identifier must contain no other characters, except a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as defined by the local operating system. This is \n on UNIX systems, including macOS. The closing delimiter must also be followed by a newline.

    TLDR: Closing identifiers should NOT be indented.

    Valid Example:

    function findAll() {
        $query=<<

提交回复
热议问题