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

后端 未结 16 1657
孤城傲影
孤城傲影 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:50

    also, look for a comment // that breaks the closing curly brace

    if (1==1) { //echo "it is true"; }

    the closing curly brace will not properly close the conditional section and php won't properly process the remainder of code.

    0 讨论(0)
  • 2020-11-22 05:50

    In my case the culprit was the lone opening <?php tag in the last line of the file. Apparently it works on some configurations with no problems but causes problems on others.

    0 讨论(0)
  • 2020-11-22 05:52

    Look for any loops or statements are left unclosed.

    I had ran into this trouble when I left a php foreach: tag unclosed.

    <?php foreach($many as $one): ?>
    

    Closing it using the following solved the syntax error: unexpected end of file

    <?php endforeach; ?>
    

    Hope it helps someone

    0 讨论(0)
  • 2020-11-22 05:56

    For me, the most frequent cause is an omitted } character, so that a function or if statement block is not terminated. I fix this by inserting a } character after my recent edits and moving it around from there. I use an editor that can locate opening brackets corresponding to a closing bracket, so that feature helps, too (it locates the function that was not terminated correctly).

    We can hope that someday language interpreters and compilers will do some work to generate better error messages, since it is so easy to omit a closing bracket.

    If this helps anyone, please vote the answer up.

    0 讨论(0)
提交回复
热议问题