|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-03-11 16:52 UTC] php4fan at gmail dot com
Description: ------------ "Unexpected <whatever>" alone is NEVER an acceptable error message. You have to tell me what you were expecting instead of what you unexpectedly found, like: "Unexpected XXXX. YYY or ZZZ expected". If that is tricky because the spectrum of legal things that could be expected is too broad, then give a hint or some context: "Unexpected X in Y", "Unmatched <this>", "incomplete <that>"... This is especially egregious with "unexpected end of file", which is usually caused by very trivial errors such an unclosed parenthesis, bracket, brace... but becomes impossible to debug with such an uninformative error message. (Unexpected end of file at line 999999 meaning the error can anywhere in a million lines) It's unbelievable that to this day such an error message is still a thing. "Unexpected end of file in 'if' condition / function body / whatever". You can easily do better than just "unexpected end of file". PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
> Please provide a concrete test case. You could have easily created one just with the information provided in my report, but here is one: ``` <?php if( ``` And here's another (see if you can spot the actual error, then imagine it being in a real-life-size file) ``` <p class="comment"> <span class="comment_text"><?php echo $comment->text; ?></span> <?php if (true) { ?> <span class="comment_edit_links"> </span> <? } ?> </p> ``` > how do you imagine a parser giving you somnething useable in case of *unparseable input* Well, I expect it to tell me why the input is unparseable. By your reasoning, no userful error message would ever be given by any parser for any syntax error.> Well, I expect it to tell me why the input is unparseable to tell you something specific it needs to be parsed > By your reasoning, no userful error message would ever be given by any parser for any syntax error "Unexpected end of file" is pretty clear! you are opening more stuff with { as you close with }> to tell you something specific it needs to be parsed Then how comes you are able to give sensible error messages in other cases? > "Unexpected end of file" is pretty clear! you are opening more stuff with > { as you close with } It could be {, it could be ( or [, even "... and then you have to find which one. And btw, it's not just not closing something that you've opened. For example this: ``` <?php $s = ```Hopefully I'm not adding fuel to the fire, but exactly what error message should this code produce? <?php class Example { public static function doThing($param) { if ($param) { echo "Doing the thing"; } }The following pull request has been associated: Patch Name: Syntax errors caused by unclosed {, [, ( mention specific location On GitHub: https://github.com/php/php-src/pull/5364 Patch: https://github.com/php/php-src/pull/5364.patch