This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 224738 - Syntax Error indication when closing parenthesis missing in php if statment
Summary: Syntax Error indication when closing parenthesis missing in php if statment
Status: RESOLVED WORKSFORME
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.2
Hardware: All All
: P4 normal (vote)
Assignee: Ondrej Brejla
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-11 06:18 UTC by berniev
Modified: 2016-09-22 17:46 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description berniev 2013-01-11 06:18:28 UTC
Product Version = NetBeans IDE 7.2 (Build 201207171143)
Operating System = Linux version 3.0.0-29-generic-pae running on i386
Java; VM; Vendor = 1.6.0_24
Runtime = OpenJDK Client VM 20.0-b12

[Product] and [Component] may be wrong above, pls fix as necessary!

Sample code:
<?php

$a = 1;

// case A: simple if using { }, error shows on if line
if (empty($a)) {
    ;
}

// case B: if then else using { }, error shows on first closing } line
if (empty($a)) {
    ;
}
else {
    ;
}

// case C: simple if without { }, error shows on if line
if (empty($a))
    ;

// case D: if then else without { }, error shows on first ; line
if (empty($a))
    ;
else
    ;
?>

In each case A through D, remove the second closing parenthesis on the if statement and observe where the error is reported:

A and C are the same, on the "if" line

D places it at the first "then" line

B places it at the end of the "then" { } block

Case B especially has bitten me many times, having me check opening and closing bracket balance before realising ..

It makes no difference if the "then" lines are just a ; as shown, or not.
Comment 1 Ondrej Brejla 2013-01-11 09:51:43 UTC
Works properly for me in 7.2.1 and 7.3dev. No errors shown. Martine, can you confirm that? Thanks in advance.
Comment 2 Martin Kanak 2013-01-11 12:10:27 UTC
Also works for me. I try it in 7.3 dev build, 7.2.1 and also 7.2. In each of them error message doesn't show up.
Comment 3 berniev 2013-01-11 22:10:02 UTC
Huh? Did you read ....

"In each case A through D, remove the second closing parenthesis on the if
statement and observe where the error is reported"

Here it is again, ~~parenthesis removed~~

<?php

$a = 1;

// case A: simple if using { }, error shows on if line
if (empty($a) {
    ;
}

// case B: if then else using { }, error shows on first closing } line
if (empty($a) {
    ;
}
else {
    ;
}

// case C: simple if without { }, error shows on if line
if (empty($a)
    ;

// case D: if then else without { }, error shows on first ; line
if (empty($a)
    ;
else
    ;
?>

I didn't want cases cross polluting, but is the same.
Also tested 7.3beta2
Comment 4 Ondrej Brejla 2013-01-12 10:16:49 UTC
Ok, errors are shown... So I don't know, what is a problem...that the errors are not self-explanatory? So you think that error messages and places (underlined chars) should be improved? Definitely yes, but it's P4 defect, or P3 enhancement. Nothing is broken and everything works as it's intended for now (parser and error handler are written to work this way). Thanks for catching that.
Comment 5 berniev 2013-01-13 01:31:40 UTC
The ~same~ error, in ~four~ similar code variants, gives ~three~ different error positions. So there is inconsistency, which surely is not intended.

The result in Case B in the example is misleading, dare I say just plain wrong, often being far from the source of the problem.

I don't know .. is there a situation where  "if (empty($a) {"  is legal?

Thank you for your attention.
Comment 6 amobilia 2016-09-22 17:46:13 UTC
Hi,
This doesn't occurs anymore on the 8.2 rc version (dev 201609210002) :
- the if line is displayed in error if the { is present
- the ; is displayed in error on the two last cases (netbeans search for a closing parenthis and found a ; )

Feel free to reopen the ticket if the problem isn't solved on your configuration.

Regards