PHP Error – Parse error: syntax error, unexpected $end in

by damonp on February 23, 2007

in Development,PHP

Parse error: syntax error, unexpected $end in … on line …

Don’t you love it when the line number indicated for an error message is the last line in the file which obviously has no error? I spent twenty minutes on this one last night.

Check for unmatched braces, brackets, parentheses or PHP tags. Nope.

Try echoing line numbers to see where execution stops. In this case no output was generated even with an echo on line #1.

Create a new file and pasted the code as Unix ASCII. Still no change.

Check PHP settings. short_open_tag is disabled by default.

[root@atlas ~]# php -i | grep short_open_tag
105:short_open_tag => On => On

Create .htaccess file:

php_flag short_open_tag on

Page loads with no errors.

Do a search for short open PHP tags in the source and replace with default tags.

Find

<?

Replace

<?php

Turn short_open_tag back off in .htacess:

php_flag short_open_tag off

Page still loads with no errors.

Popularity: 35%

Most Popular Posts

Damon Parker is a freelance sysadmin and web developer in Texas. He specializes in server setup, server security and high performance server configurations. Need help setting up a web server or getting a server back online after a crash or hack? Email Damon

{ 6 comments… read them below or add one }

zeyad shorman March 4, 2009 at 3:59 pm

i have error on my php code ,the error is Parse error: syntax error, unexpected $end in E:\AppServ\www\constant.php on line 17

Three plus five

three plus five
demonstrate use of number variables
$x $y = $sum
$x – $y = $dif
$x * $y = $prod
$x / $y = $quotient
HERE;
?>

Reply

zeyad shorman March 4, 2009 at 4:01 pm

this one $x $y = $sum
$x – $y = $dif
$x * $y = $prod
$x / $y =$quotient
HERE;
?>

Reply

sasi August 18, 2010 at 11:04 pm

1. $page .= <<<EOD
2. © $year $copyright
3.
4.
5. EOD;
6. return $page;

see to that you have no spaces between line 1&2 also bet line 5 & 6. This would resolve the error. for eg: go to line 1 hit del key until u have no space between EOD(of line 1) and <(of line 2) then hit enter
}

Reply

Whatever October 17, 2011 at 3:56 pm

Once it happened that everything was fine but I was getting this error. It made me mad, but then at the end, the error was something to laugh about. I was using cuteFTP and uploading files to 000webhost, it so happened that the file transfer terminated somewhere in the middle, such that whole file was not transfered and the file containing missing code, was up on the server, that;s where the error was coming.

Reply

al November 16, 2011 at 12:07 pm

beat my head up against this for a day. it works on my production server, but failed on my testing server. I simply could NOT figure it out. turns out it was in fact the short opening PHP tags.

thanks…

Reply

themhz January 14, 2012 at 8:23 am

thanx , realy thanx, it solved my problem . my setup is wamp with joomla 1.7
and i when to php->php settings->open tag tag must be ticked

Reply

Leave a Comment

Previous post:

Next post: