Php-parser: invalid ast for `{` and `}`

Created on 28 Aug 2019  路  8Comments  路  Source: glayzzle/php-parser

Input:

$var = $foo->bzr_{1};
$var = $foo->bzr_{'string'};
$var = $foo->bzr_{$baz};
$var = $foo->bzr_{$baz->foo};
$var = $foo->bzr_{$var ? 'one' : 'two'};

Parsed as encapsed with offset, but it is just offsetlookup with curly brackets

Should be parse as:

$var = $foo->bzr_[1];
$var = $foo->bzr_['string'];
$var = $foo->bzr_[$baz];
$var = $foo->bzr_[$baz->foo];
$var = $foo->bzr_[$var ? 'one' : 'two'];
bug AST high-pri

Most helpful comment

All 8 comments

Very very high priority

/cc @ichiriac can you help me with this?

not sure about this :

$var = $foo->bzr_{$var ? 'one' : 'two'};
// !=
$var = $foo->bzr_[$var ? 'one' : 'two'];
// lets say var is true :
$foo->bzr_{$var ? 'one' : 'two'} ==  $foo->bzr_one != $foo->bzr_['one'];

Can you confirm ?

It is same code, look

$var = true;

$foo = new class {
    var $bzr_ = ['one' => 'foo'];
};

echo $foo->bzr_{$var ? 'one' : 'two'};
echo $foo->bzr_[$var ? 'one' : 'two'];

confirmed, I'll make a fix, I'll need a curly property on offset node in order to keep track if it was from a { or from a [

We can implement curly prperty in future, it is already deprecated, and rarely used

thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexander-akait picture alexander-akait  路  9Comments

takashiki picture takashiki  路  7Comments

alexander-akait picture alexander-akait  路  8Comments

alexander-akait picture alexander-akait  路  7Comments

Rivendall picture Rivendall  路  6Comments