11

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Karthik Malla
  • 5,570
  • 12
  • 46
  • 89
  • 4
    you missed a closing brace somewhere – Bhuvan Rikka Dec 21 '12 at 13:00
  • I tried the code, and it ran until it groused about base_url. Did you make a mistake in copying it? – RonaldBarzell Dec 21 '12 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?](http://stackoverflow.com/q/12769982/367456) – hakre Dec 21 '12 at 13:02
  • I checked in almost all the online tools at http://www.google.co.in/search?q=php+online+syntax+check&aq=0&oq=php+online+sy&sugexp=chrome,mod=0&sourceid=chrome&ie=UTF-8#hl=en&sugexp=les%3B&gs_rn=1&gs_ri=serp&pq=share%20code%20online&cp=12&gs_id=2x&xhr=t&q=php+syntax+checker&pf=p&tbo=d&sclient=psy-ab&oq=php+syntax+c&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.1355534169,d.aGc&fp=aaf6447fe4e1119c&bpcl=40096503&biw=1280&bih=699 – Karthik Malla Dec 21 '12 at 13:02
  • And you have to load the `url` helper before using `base_url()` – Bhuvan Rikka Dec 21 '12 at 13:02
  • If that's a } or ; IDE must point out the issue. I tested in various IDEs but no IDE pointed the error. – Karthik Malla Dec 21 '12 at 13:09
  • You do not really expect somebody to go through your tremendous file just to fiddle with your parsing issue, won't you? – hakre Dec 21 '12 at 13:17

3 Answers3

61

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

kmkaplan
  • 18,655
  • 4
  • 51
  • 65
  • 7
    You should include what `short_open_tag` does, and what it should be set to and why in the answer itself. – Nathaniel Ford May 19 '14 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 Oct 08 '14 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 – ChicagoSky Dec 01 '14 at 02:57
  • 1
    Have to say this saved me from a potential head ache as well. – Halsafar Feb 07 '15 at 21:52
  • 1
    In case you are using command line, you can type `php -i | grep short_open_tag ` instead of ``. I guess default value is Off which means you have to use `` instead of only ` ?>` – EAmez Apr 23 '21 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.
Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
3

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

Zagor23
  • 1,953
  • 12
  • 14