From: php at richardneill dot org Operating system: Linux PHP version: 5.2.9 PHP Bug Type: Feature/Change Request Bug description: wish: syntax error, unexpected $end should show start point
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 bug report at http://bugs.php.net/?id=47883&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47883&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47883&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47883&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47883&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47883&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47883&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47883&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47883&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47883&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47883&r=support Expected behavior: http://bugs.php.net/fix.php?id=47883&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47883&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47883&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47883&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47883&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47883&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47883&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47883&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47883&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47883&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47883&r=mysqlcfg