z7zmey / php-parser

PHP parser written in Go

Home Page:https://php-parser.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty array elements and trailing comma in array literals

quasilyte opened this issue · comments

At some point, php parser started to parse [1, 2,] as array of 3 elements where the last array element consisting of key=nil and val=nil.

If we dig further, it also parses something like [,,,] as an array of 4 (empty) elements.

Is it intended behavior?

Relevant comment: VKCOM/noverify#108 (comment)
Seems like it's not an issue.

As @YuriyNasretdinov mentioned, it is a way to represent skipped elements in a list.
Unfortunately array and list use the same syntax rules to parse their items, so PHP engine checks empty elements at the compile phase https://github.com/php/php-src/blob/775e86344f05f3332463003230ef93df8167ab6c/Zend/zend_compile.c#L7666

Thanks. That resolves my question.