PHP Parse error: syntax error, unexpected T_IF

If you encounter bugs, errors or crashes, please report them in this section so we can try to fix it!
User avatar
ECC Developer 2006-2016
Posts: 9059
Joined: 27 Aug 2006, 01:17
Location: Deventer, The Netherlands

PHP Parse error: syntax error, unexpected T_IF

Unread post by Phoenix » 09 Jan 2010, 13:18

I was browsing in the bugreports, and i saw this:

Code: Select all

[29-nov-2009 12:00:25] PHP Parse error: syntax error, unexpected T_IF in C:\emuControlCenter\ecc-system\manager\cOs.php on line 174
PHP Error explanation and example:
An example might be helpful at this point. Take a look at the PHP code shown below:


$b = "somevalue"

if($b == "somevalue"){
print "Hello world!";


The mistake is on the "$b =" line (no semicolon ending the statement), so the error should be "parse error: expected ; on line 3", right? Not according to the interpreter.

Parse error: parse error, unexpected T_IF in c:\program files\apache group\apache\htdocs\ereg2.php on line 4

On line 4, the if() syntax is perfect. So what is the interpreter getting confused from? The clue is the "unexpected T_IF" part. When an "unexpected T_???" error occurs, it means that the interpreter encountered its respective reserved word where it shouldn't be. T_IF for if(), T_WHILE for while(), T_FOR for for(), etc.

Luckily, there are a few easy causes for these errors:
The statement wasn't ended with a semicolon (;), like in the example above.
A quote was not properly escaped (' instead of \' or " instead of \") in a string.
Can some help me to track it down, or to catch/recreate it?, Micha?
Sebastiaan Ebeltjes | ECC Developer 2006-2016 | ECC Forum Admin | Phoenix Interactive WebMaster
[- ECC programs -]
eccUpdate, eccScriptSystem, GtkThemeSelect, DatFileUpdater (DFU), ImagePackCenter (IPC), eccDiagnostics, 3dGallery, iccImageInject
eccKameleonCode, eccCreateStartmenuShotcut, eccThirdPartyConfig (TPC), EmuMoviesDownloader (EMD), eccVideoPlayer
MobyGamesImporter (MGI), ECC Amiga GetGemusConfig.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest