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 258959 - [PHP7] Array class constant element reference within isset() marked: Syntax error: unexpected: '[' after: 'OR' expected: '('
Summary: [PHP7] Array class constant element reference within isset() marked: Syntax e...
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.2
Hardware: All All
: P2 normal (vote)
Assignee: junichi11
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-21 16:34 UTC by BlameFate
Modified: 2016-05-25 01:51 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 BlameFate 2016-04-21 16:34:18 UTC
function map_host(){
	if(isset(Domain::HOST_MAPPINGS[$_SERVER['HTTP_HOST']])){
		return Domain::HOST_MAPPINGS[$_SERVER['HTTP_HOST']];
	}else{	return $_SERVER['HTTP_HOST'];
}	}

class Domain{
	const HOST_MAPPINGS=['www.example.com'=>'example.com'];
}

Line 2 in the code above is marked with the misidentified syntax error described in the title of this report:
Syntax error: unexpected: '[' after: 'OR' expected: '('

There should be no syntax error warning here from NetBeans (the code runs fine in PHP7!)

While Line 2 has been highlighted as a syntax error, Line 3 has not - so it only seems to happen inside isset().
Comment 1 BlameFate 2016-04-21 16:34:53 UTC
Possibly related to Bug 250579.
https://netbeans.org/bugzilla/show_bug.cgi?id=250579
Comment 2 BlameFate 2016-04-21 16:37:55 UTC
The syntax error warning is retained even if we replace, on Line 2, $_SERVER['HTTP_HOST'], with a string, 'test'.
Comment 3 Tomas Mysik 2016-04-22 05:47:17 UTC
@junichi11: Junichi, would you like to have a look at this issue? Thanks.
Comment 4 junichi11 2016-04-22 11:55:16 UTC
(In reply to BlameFate from comment #1)
> Possibly related to Bug 250579.

I guess that it is not related to it (I can be wrong). Because your code is invalid in PHP5.6 or older and it works fine in PHP7.

more simple examples:
<?php
const A = ["test"];
var_dump(isset("test"[0])); // PHP7: bool(true) , PHP5.6: Fatal Error
var_dump(isset([1][0]));    // PHP7: bool(true) , PHP5.6: Fatal Error
var_dump(isset(A[0]));      // PHP7: bool(true) , PHP5.6: Fatal Error


(In reply to Tomas Mysik from comment #3)
> @junichi11: Junichi, would you like to have a look at this issue?

Tomas, I'll try it.

Thanks.
Comment 5 Tomas Mysik 2016-04-22 12:08:53 UTC
I see, thanks Junichi for explanation.
Comment 6 Tomas Mysik 2016-05-19 10:33:07 UTC
Increasing to P2, we need to fix this since from PHP 7 constants can contain arrays so accessing their values will happen very often.

Thanks.
Comment 7 Tomas Mysik 2016-05-19 10:33:57 UTC
@junichi11: Junichi, please if you start working on this issue, reassign it to yourself first. Thanks.
Comment 8 junichi11 2016-05-19 11:20:23 UTC
(In reply to Tomas Mysik from comment #7)
> @junichi11: Junichi, please if you start working on this issue, reassign it
> to yourself first. Thanks.

I'll do it. Thanks.
Comment 9 Tomas Mysik 2016-05-19 11:27:34 UTC
(In reply to junichi11 from comment #8)
> I'll do it. Thanks.

Thanks a lot!
Comment 10 junichi11 2016-05-24 03:13:35 UTC
Fixed.

The following case is not resolved because $object->test()() is not supported yet:

isset($object->test()()[0]);

http://hg.netbeans.org/web-main/rev/29c77ad37eca

Thanks.
Comment 11 Quality Engineering 2016-05-25 01:51:07 UTC
Integrated into 'main-silver', will be available in build *201605250002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/29c77ad37eca
User: Junichi Yamamoto <junichi11@netbeans.org>
Log: #258959 - [PHP7] Array class constant element reference within isset() marked: Syntax error: unexpected: '[' after: 'OR' expected: '('