Parse error: syntax error, unexpected $end

Last update on July 31, 2009 12:50 PM by jak58
Published by jak58

Parse error: syntax error, unexpected $end







When you program in PHP,it is most propable that you have encounterd such error:
Parse error: syntax error, unexpected $end in Command line code on line 1


What causes this error?

In fact, this error means that PHP has finished analyzing your code, but you forgot to close a symbol somewhere in your page or in those that were included.

Situations:
  • you forgot to close a quote, so PHP is continuing to analyze your code until it finds the closing quotation mark.
  • You forgot to close a bracket, so from the last opening, Php considers all the code that follows as part of a block that never ends.
  • You forgot to close a parenthesis, so from the last open parenthesis, Php considers all the code that follows as part of a specific block (condition, arguments of functions etc ...) that does not end.
  • You forgot a comma, so for PHP there is an instruction in your code that has no end.



Therefore, unnecessary to refer to the line indicated by Php as the origin of the error. Php tell you that the problem comes from the last line, while the origin can be located just anywhere in the page or pages that are included.

Examples of codes that cause this error.

Here are some examples of codes that are causing this error.

<?
if ($condition){
     echo "true";
?>


Forgot to close a quote:

<?
echo "test;
?>

Forgot to close a parenthesis:

<?
mysql_query("mysite", "logon", "thisisnotasqlserver.com" ;
?>



Forget a semicolon:

<?
if ($test){
echo '1'
}
?>

==How to fix/avoid this error==

This is often due to a poorly organized presentation of your code. Especially remember to indent your code well, to visually distinguish the different blocks.

Example of a clean code

//Equivalent of array_reverse()
function inverse_table($table)
{
    $ret = array();
    if (is_array($table) ){
        for($i=sizeof($table) - 1; $i >= 0; $i++)
        {
            $ret[] = $table[$i];
        }
    }
    return $ret;
}


Example of a non-indented code, harder to debug:

function inverse_table($table)
{
$ret = array();
if (is_array($table) ){
for($i=sizeof($table) - 1; $i >= 0; $i++)
{
$ret[] = $table[$i];
}
}
return $ret;
}



If you encounter this error, please note that it is not necessarily the end of your code, for example, omitting an accolade may be at the very beginning of your code, even if your file is 1000 lines.
Best answers for « Parse error: syntax error, unexpected $end » in :
Parse error, unexpected T_STRING, expecting ',' or ';' Show Parse error, unexpected T_STRING, expecting ',' or ';' Example 1 How to solve the problem Example 2 In PHP, a common problem that may arise while creating a PHP file is the parse error T_String. This happens when a programmer (or a...
Epson Error Message [End of Service Life] ShowEpson Error Message [End of Service Life] Download and install SCC Service Utility If your Epson printer has been displaying the error message End of Service Life¯, hold it before planning to buy a new one. The problem does not come...
Epson parts inside your printer are at the end of their life ShowEpson – parts inside your printer are at the end of their life After a certain period of time and of consequent use of your printer, you may have come across the error message parts inside your printer are at the end of their life. In...
ORA-00600 internal error code, arguments ShowORA-00600 internal error code, arguments This error code is native to internal exceptions from the Oracle programs. It indicates that the process has encountered an unexpected low. It may be due to timeout A corrupted file crash...
Download Windows Error Message Creator ShowThe chains which alert on viruses do not work any more, then made more extremely. If you want to scare your colleagues or your friends on their computer, the best means is of their envoy a message of error. Windows Error Message Creator is a very...
Error checking ShowError checking Binary encoding is very practical for use in electronic devices such as computers, in which information can be encoded based on whether an electrical signal is present or not. However, this electrical signal may suffer disturbances...