z7zmey / php-parser

PHP parser written in Go
https://php-parser.com
MIT License
941 stars 63 forks source link

Empty array elements and trailing comma in array literals #90

Closed quasilyte closed 5 years ago

quasilyte commented 5 years ago

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?

quasilyte commented 5 years ago

Relevant comment: https://github.com/VKCOM/noverify/pull/108#issuecomment-497758847 Seems like it's not an issue.

z7zmey commented 5 years ago

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

quasilyte commented 5 years ago

Thanks. That resolves my question.