ID: 47883 Comment by: simon at stienen dot name Reported By: php at richardneill dot org Status: Open Bug Type: Feature/Change Request Operating System: Linux PHP Version: 5.2.9 New Comment:
I agree, having an actual line number would be nice. I'd consider it more important to know what kind of token caused the unexpected $end. Interestingly, it tells me if it's missing a ) at the end, but for " or }, it's just "unexpected $end". Previous Comments: ------------------------------------------------------------------------ [2009-04-02 22:01:03] php at richardneill dot org Description: ------------ If I have a script with a syntax error, such as a missing '}' somewhere, PHP will helpfully tell me that there's a problem, but direct me to look in the wrong place. The error message is as follows: Parse error: syntax error, unexpected $end in [FILENAME] at [NUMBER_OF_LAST_LINE] This is unhelpful for 2 reasons. * It isn't clear what type of syntax error would cause this - there's no way to know what character PHP was expecting to see. * I have no easy way of finding the offending line where the bug really lies, apart from commenting out parts of the source and doing a binary-search within it. Essentially, PHP is saying "You have an error, but I won't tell you where". Expected result: ---------------- The following would be clearer and *far* more helpful. Syntax error: unexpected $end in [FILENAME] at LINENUM: missing an expected '}' character. (The corresponding, unmatched '{' is probably at line xxx.) Of course, it's not always possible for PHP to know which open-brace is the unmatched one - however, it could usually take a reasonable best guess by iterating *backwards* through the source, and doing: 1 $nest_depth=0 2 If a '}' is encountered, $nest_depth++ 3 If a '{' is encountered, $nest_depth-- 4 If $nest_depth == -1, we have located the open-brace that isn't closed. Print LINENUM. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47883&edit=1