php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #17101 Parse errors involving control structures should indicate the start of it
Submitted: 2002-05-08 14:36 UTC Modified: 2014-12-30 10:41 UTC
Votes:5
Avg. Score:4.6 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:3 (75.0%)
From: destes at ix dot netcom dot com Assigned:
Status: No Feedback Package: *General Issues
PHP Version: Any OS: Irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
3 - 3 = ?
Subscribe to this entry?

 
 [2002-05-08 14:36 UTC] destes at ix dot netcom dot com
A common scripting oversight is to forget to properly close control structures bounded by curly braces such as if:

if ($var) {
	$foo = 1;
	$bar = 2;
/* forgot the } */

...

When parsing this, PHP reports that the error occurred on the last line of the script - however many lines there are.  For scripts that run many thousands of lines, and contain hundreds of control structures, this means a huge amount of time spent going over the entire code looking for the bad structure.

It occurs to me that PHP should be able to determine where the START of the unended control structure is, and raise the parse error indicating that line (instead of the last line of the document).  Adding this feature would greatly decrease debug times for people who occasionally make errors like these.

Thanks,
Steve

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-08 14:54 UTC] sander@php.net
There is no way how PHP can detect it.
Consider the following (bogus) script:
if($foo) {
...
if($bar) {
...
}
How can PHP know which brace is missing?
It can be
if($foo) {
    ...
}
if($bar) {
    ...
}
but it can also be
if($foo) {
    ...
    if($bar) {
        ...
    }
}
If you have a good idea how to detect it, please let us hear.
 [2002-05-08 17:08 UTC] destes at ix dot netcom dot com
Even providing the start of the If structure that is unclosed - even if it has nested Ifs - would still provide useful functionality.  When in doubt, go with the earliest one.  That in itself will greatly narrow the range of possibilities.

I should also note that in your example, in both possible cases, it is the closing brace for the FIRST if that is missing.  Even if the second one were nested inside the first one, the missing brace would be for the first If statement, so you could safely report "Parse error: Unclosed If Structure beginning on line ____" and it would be greatly useful.

I admit that there is no way to determine where the closing brace should go.  However, you can (At the very least) determine the highest level If structure which was never closed - and report that line.

Please let me know if i'm not making sense, which happens often =)

Thanks for your blindingly-fast reply.

-Steve
 [2002-05-08 18:36 UTC] destes at ix dot netcom dot com
Reopening issue, see comments.
 [2003-07-13 18:43 UTC] madsen at sjovedyr dot dk
Just reporting that a } might be missing somewhere would be a great improvement, at least until the above mentioned solution is implemented...

I've had heaps of ppl asking me what the error in "this line (?>)" was.. :)
 [2014-04-30 23:03 UTC] levim@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues -Operating System: All +Operating System: Irrelevant -PHP Version: 4.1.2 +PHP Version: Any
 [2014-04-30 23:03 UTC] levim@php.net
Is there still interest in this?
 [2014-07-16 00:55 UTC] yohgaki@php.net
I think this should be closed as 'wont fix'.
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 12:01:27 2024 UTC