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 271711 - PHP7: Unrecognized syntax for arrays returned by anonymous object methods
Summary: PHP7: Unrecognized syntax for arrays returned by anonymous object methods
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: issues@php
Depends on:
Reported: 2017-10-26 22:31 UTC by parseword
Modified: 2017-10-26 22:31 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description parseword 2017-10-26 22:31:41 UTC

In PHP 7, when an anonymous object's method returns an array, it's possible to access the returned array elements directly by index (for an unkeyed array) or by key (for a keyed array). Given the following code,


class Produce 
    private $fruits = array('red'=>'apple', 'yellow'=>'banana');
    private $vegetables = array('beet', 'potato', 'zucchini');
    public function getFruits() {
        return $this->fruits;
    public function getVegetables() {
        return $this->vegetables;

$foo = ((new Produce())->getFruits())['yellow'];

$bar = ((new Produce())->getVegetables())[1];



This assignment syntax is valid beginning with PHP 7.0; the output is:

string(6) "banana"
string(6) "potato"


Actual Results:

NetBeans 8.2 doesn't recognize this syntax even when the project properties "PHP Version" is set to 7.0. It generates this error:

    Syntax error: unexpected [ after )

Expected Results:

No error message, syntax recognized as valid if the project "PHP Version" setting is set to 7.0 or higher