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 250579 - "Unexpected '[' after identifier" when declaring a const and assigning a value from an array to it
Summary: "Unexpected '[' after identifier" when declaring a const and assigning a valu...
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.0.2
Hardware: All All
: P3 normal with 4 votes (vote)
Assignee: Tomas Mysik
URL:
Keywords:
: 251219 251489 254474 257362 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-02-20 13:10 UTC by reasv
Modified: 2018-02-23 16:51 UTC (History)
10 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
A screenshot of the issue (1.79 KB, image/png)
2015-02-20 13:10 UTC, reasv
Details
same issue here (56.71 KB, image/png)
2015-03-13 20:38 UTC, touhonoob
Details
patch (2.22 MB, patch)
2016-03-24 10:12 UTC, junichi11
Details | Diff
Netbeans 8.2 complaining about constant array syntax (17.08 KB, image/png)
2016-10-26 13:13 UTC, Jack_Brody
Details

Note You need to log in before you can comment on or make changes to this bug.
Description reasv 2015-02-20 13:10:29 UTC
Created attachment 152116 [details]
A screenshot of the issue

I defined a const TABLES with

const TABLES = array('users', 'admins');

And then I defined another const, which should contain the first element of TABLES, USERS:

const USERS = TABLES[0];

But this line is highlighted as an error by NetBeans, with the following explanation:

"
Syntax error
unexpected:    [
after: Identifier 'TABLES'
expected: variable, instanceof, as, implements [ETC, list goes on] 
"

Note that the project is set as PHP 5.6, and my server running 5.6 does NOT give me errors or notices when I try to run this code, in fact the value of USERS is as expected.
Of course, all errors and notices are enabled on my test server, since it's running XAMPP.
Comment 1 touhonoob 2015-03-13 20:38:08 UTC
Created attachment 152614 [details]
same issue here

Product Version: NetBeans IDE 8.0.2 (Build 201411181905)
Comment 2 junichi11 2015-10-21 04:52:36 UTC
*** Bug 251489 has been marked as a duplicate of this bug. ***
Comment 3 junichi11 2015-10-21 04:56:42 UTC
*** Bug 251219 has been marked as a duplicate of this bug. ***
Comment 4 junichi11 2015-10-21 14:33:27 UTC
*** Bug 254474 has been marked as a duplicate of this bug. ***
Comment 5 Paulaner 2015-12-18 15:55:21 UTC
The same on MAC OSX Netbeans 8.1
Comment 6 junichi11 2016-01-06 02:35:42 UTC
*** Bug 257362 has been marked as a duplicate of this bug. ***
Comment 7 adipinto 2016-01-30 11:40:04 UTC
The same on Linux Netbeans 8.1
Comment 8 junichi11 2016-03-24 10:12:09 UTC
Created attachment 158989 [details]
patch
Comment 9 junichi11 2016-03-24 10:24:02 UTC
I've created a patch.

I also fixed GoToDeclaration and MarkOccurrence. But the following case doesn't work yet. I'll submit it as a new issue later.

$constantClass = new ConstantClass();
$constantClass::C^ONSTANT; // here : also method and field

Tomas, Could you please review it when you can make time?

Thanks!
Comment 10 Tomas Mysik 2016-03-24 10:56:30 UTC
(In reply to junichi11 from comment #9)
> Tomas, Could you please review it when you can make time?

Great work, Junichi! Thanks a lot!
Comment 11 Tomas Mysik 2016-03-29 08:35:19 UTC
Patch applied, thanks a lot for it, Junichi!

http://hg.netbeans.org/web-main/rev/0bcf8fbd05f4
Comment 12 Quality Engineering 2016-03-30 01:38:50 UTC
Integrated into 'main-silver', will be available in build *201603300001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/0bcf8fbd05f4
User: Tomas Mysik <tmysik@netbeans.org>
Log: #250579 - "Unexpected '[' after identifier" when declaring a const and assigning a value from an array to it

Patch contributed by junichi11@netbeans.org.
Comment 13 photonensammler 2016-04-07 04:21:57 UTC
Because this bug I have tested NetBeans IDE Build 2016046001.
This bug is fixed but now I get a new syntax error:

Example:

<html>
  <head>
    <title>Title</title>
  </head>
  <body>
    <span id="<?php echo $my_var; ?>">anything other txt</span>
  </body>
</html>

For the <span ... line is the error message:

Bad value " " for attribute "id" on element "span":An ID must not contain whitespace.
An ID consists of at least one character but must not contain any whitespace.
Comment 14 junichi11 2016-04-07 06:04:15 UTC
(In reply to photonensammler from comment #13)
> Because this bug I have tested NetBeans IDE Build 2016046001.
> This bug is fixed but now I get a new syntax error:
> 
> Example:
> 
> <html>
>   <head>
>     <title>Title</title>
>   </head>
>   <body>
>     <span id="<?php echo $my_var; ?>">anything other txt</span>
>   </body>
> </html>
> 
> For the <span ... line is the error message:
> 
> Bad value " " for attribute "id" on element "span":An ID must not contain
> whitespace.
> An ID consists of at least one character but must not contain any whitespace.

Please don't change status. If you find some problems, please submit them as new issues.

BTW, I cannot reproduce it in a php file. So, I guess that you are using an html file.

Thanks.
Comment 15 lolka_bolka 2016-04-08 13:48:54 UTC
Why is this issue is closed?

This problem is still persist in 8.1
Comment 16 junichi11 2016-04-08 14:29:12 UTC
(In reply to lolka_bolka from comment #15)
> Why is this issue is closed?

Because it was already fixed and it is available in the dev build[1].
So, please try testing it if you are interested in it. Then, if you find some problems, please report them as new issues.

> This problem is still persist in 8.1

Perhaps, it will be available in 8.2(not 8.1). 
Basically, fixed issues will be available in the next NetBeans version.

[1] http://bits.netbeans.org/download/trunk/nightly/latest/ 

Thanks.
Comment 17 Jack_Brody 2016-10-26 13:13:02 UTC
Created attachment 162647 [details]
Netbeans 8.2 complaining about constant array syntax

Just installed 8.2, this issue is still present.
Comment 18 Jack_Brody 2016-10-26 13:18:03 UTC
The issue was supposed to be fixed in 8.2. 

I have fresh installation of NB 8.2 and it still does not respect the right of PHP's constant array for life. :-)
Comment 19 junichi11 2016-10-26 13:51:04 UTC
(In reply to Jack_Brody from comment #18)
> The issue was supposed to be fixed in 8.2. 
> 
> I have fresh installation of NB 8.2 and it still does not respect the right
> of PHP's constant array for life. :-)

Could you submit it as a new issue?

Thanks.
Comment 20 colan 2018-02-23 16:51:56 UTC
If any of you have posted a follow-up issue, please post a link here so that the rest of us can track it.  Thanks!