PHP Error Messages - unexpected T_PRINT | |
PHP Error Messages - What do they mean?The PHP rookie programmer encounters certain types of error messages over and over again. Its nice to know what to look for, because although the PHP engine gives a line number the descriptions of the errors are sometimes less than intuitive! Worst of all the line number is the line on which the parser becomes aware of the error which is NOT always the line the error is on! Oh how I miss staying up to 2AM re-examining and rewriting the same line line of perfectly valid code over and over again... Here is the thing I wish somebody had given me when I started - a list of common php error messages and advice on how to get out of the nasty stuff!
PHP Parse error: syntax error, unexpected T_PRINT, expecting ',' or ';' in ... on line 4This little beauty is what usually crops up when you miss out a semi-colon (;) at the end of a line, in a For statement or leave out a comma in a list or array. The nasty thing about this error is it often does not report the correct line number but the number it gives is in fact the line below. Examples:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in ....... on line 41This has exactly the same cause - the line above the line given will have the missing semi-colon.
PHP Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... on line 248I often hate seeing this. It means that you have a string value someplace that is not closed properly, either a missing quote or double quote or maybe one or several too many if you have been mixing single or double quotes. The truly horrible thing about this error is that it could be anyplace in your script and the line number it gives you is always the last line! For example these will definitely do it:
PHP Parse error: syntax error, unexpected ';' in ... on line 23In this case you will at least have the line number correct! The message is telling you that something is missing before the offending semi-colon. This may be that while you were cutting and pasting you accidentally created a blank line with just a semi-colon on or more often a missing trailing bracket from a function call like: buildlink($lurl,$lktext ;Rarely this message may also occur if you put a semicolon where it should not be like: for ($i=0;$i<=10; $i++;){ (the last statement should not have a semi-colon)
Other PHP ErrorsThe good news is that the other errors explain themselves pretty well so long as you read the error message thoroughly. Its probably worth me mentioning file permissions. If you using the script to create files then your script has to have the permissions to create files in the directory that they are in. You can set the directory so that everybody has rights (chmod 0777) but this is insecure. The best way around this is to use a script to create the directory to start with, rather than ftp or a file manager. That way the owner of the directory is the scripting engine and it can do what it likes with the files. The downside to this is that if you manually want to delete the files or edit them you cant do it because you do not own the directory or the files. To fix this you can write a utility to chmod files to 0777 (universal) then back to 0644 (owner only) when you have altered them.What to do if you cant find an error?Panic? Only joking! Save your script into another file. Remove bits of code from your file one at a time, make sure these bits are self standing bits (like functions) and run the file. If it produces the same error then your bad code is still in the file, if not then it was in the chunk you took out. If a different error is produced then the code you saved was not self-standing. Try again! It sounds like a lot of work but if you eliminate almost half the script with the first try and carry on cutting the code in near halves then you will find the real errant line within 10 tries even if you have 1000 lines of code. Often just narrowing it down to 40-50 lines makes it spottable.We hope you have found this article helpful. If it saved your bacon then a link back to www.webmaster-a.com would be appreciated!
|
Useful Pages
PHP Process all files Referrersbookmark hitwww.google.com ... www.google.de www.google.pl ... vidvain.com www.google.ca ozinengland.com www.google.com.hk www.google.co.th ... www.arcopedico.org www.google.se www.google.com.tw ... denvang.com baerbykes.com landroidapps.com www.google.com.br www.google.hu ... www.babadorie.net ... www.google.co.in ... ... ... ... www.google.com.au ... www.baidu.com www.google.hr www.google.com.ph www.google.com.my www.scape-xp.com www.google.pt www.google.co.za www.google.co.il ... ... www.hgt435lop345.com ... www.phone-no.net www.google.am This list of people who link to this PHP Code Snippet page is automagically maintained. Link to us, send traffic, and get listed. Simple. |