12

I am getting an unexpected end of file error on my CodeIgniter View.

I have pasted the PHP code at http://codepad.org/S12oXE4t.

This code passed various online PHP syntax tests, but I don't know why still it shows me the below error while I was trying to run in WAMP Server.

Parse error: syntax error, unexpected end of file in
 E:\wampserver\www\CodeIgniter\application\views\layouts\default.php on line 676

For reference, line 676 is the last line in the code. What did I do wrong?

7
  • 4
    you missed a closing brace somewhere Commented Dec 21, 2012 at 13:00
  • I tried the code, and it ran until it groused about base_url. Did you make a mistake in copying it? Commented Dec 21, 2012 at 13:02
  • 4
    In case you encounter an error message you don't understand, it's not that wrong to pay a visit to: Reference - What does this error mean in PHP?
    – hakre
    Commented Dec 21, 2012 at 13:02
  • I checked in almost all the online tools at google.co.in/… Commented Dec 21, 2012 at 13:02
  • And you have to load the url helper before using base_url() Commented Dec 21, 2012 at 13:02

3 Answers 3

61

Check your short_open_tag setting (use <?php phpinfo() ?> to see its current setting).

5
  • 7
    You should include what short_open_tag does, and what it should be set to and why in the answer itself. Commented May 19, 2014 at 21:36
  • 1
    I would vote you thousands times if I could, just saved me after of 4 hours smashing my head on the keyboard trying to fix disasters from some random wotsit whom at the end it came up that he only likes to put deprecated shorttags everywhere.
    – MacK
    Commented Oct 8, 2014 at 13:52
  • Wow!! this is such an important item - I wasted almost 2 hours trying to trouble shoot when the solution is this simple
    – SeaSky
    Commented Dec 1, 2014 at 2:57
  • 1
    Have to say this saved me from a potential head ache as well.
    – Halsafar
    Commented Feb 7, 2015 at 21:52
  • 1
    In case you are using command line, you can type php -i | grep short_open_tag instead of <?php phpinfo() ?>. I guess default value is Off which means you have to use <?php ?> instead of only <? ?>
    – EAmez
    Commented Apr 23, 2021 at 11:41
21

Unexpected end of file means that something else was expected before the PHP parser reached the end of the script.

Judging from your HUGE file, it's probably that you're missing a closing brace (}) from an if statement.

Please at least attempt the following things:

  1. Separate your code from your view logic.
  2. Be consistent, you're using an end ; in some of your embedded PHP statements, and not in others, ie. <?php echo base_url(); ?> vs <?php echo $this->layouts->print_includes() ?>. It's not required, so don't use it (or do, just do one or the other).
  3. Repeated because it's important, separate your concerns. There's no need for all of this code.
  4. Use an IDE, it will help you with errors such as this going forward.
2
  • If that's a } or ; IDE must point out the issue. I tested in various IDEs but no IDE pointed the error. Commented Dec 21, 2012 at 13:09
  • 3
    @lock Not if the error is in an include somewhere. Commented Dec 21, 2012 at 13:09
3

Usually the problem is not closing brackets (}) or missing semicolon (;)

1
  • If that's a } or ; IDE must point out the issue. I tested in various IDEs but no IDE pointed the error. Commented Dec 21, 2012 at 13:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.