@@ -126,33 +126,6 @@ module.exports = {
126126 if ( is_static_lookup && this . token === this . tok . T_OBJECT_OPERATOR ) {
127127 this . error ( ) ;
128128 }
129-
130- if ( this . token === this . tok . T_VARIABLE ) {
131- const inner = this . node ( "variable" ) ;
132- name = this . text ( ) . substring ( 1 ) ;
133- this . next ( ) ;
134- what = this . node ( "encapsed" ) (
135- [ what , inner ( name , false ) ] ,
136- null ,
137- "offset"
138- ) ;
139- if ( what . loc && what . value [ 0 ] . loc ) {
140- what . loc . start = what . value [ 0 ] . loc . start ;
141- }
142- } else if ( this . token === "{" ) {
143- // EncapsedPart
144- const part = this . node ( "encapsedpart" ) ;
145- const expr = this . next ( ) . read_expr ( ) ;
146- this . expect ( "}" ) && this . next ( ) ;
147- what = this . node ( "encapsed" ) (
148- [ what , part ( expr , true ) ] ,
149- null ,
150- "offset"
151- ) ;
152- if ( what . loc && what . value [ 0 ] . loc ) {
153- what . loc . start = what . value [ 0 ] . loc . start ;
154- }
155- }
156129 break ;
157130 case this . tok . T_VARIABLE :
158131 what = this . node ( "variable" ) ;
@@ -209,23 +182,30 @@ module.exports = {
209182 }
210183 break ;
211184 case "[" :
185+ case "{" : {
186+ const backet = this . token ;
187+ const isSquareBracket = backet === "[" ;
212188 node = this . node ( "offsetlookup" ) ;
213189 this . next ( ) ;
214190 offset = false ;
215191 if ( encapsed ) {
216192 offset = this . read_encaps_var_offset ( ) ;
217- this . expect ( "] ") && this . next ( ) ;
193+ this . expect ( isSquareBracket ? "]" : "} ") && this . next ( ) ;
218194 } else {
195+ const isCallableVariable = isSquareBracket
196+ ? this . token !== "]"
197+ : this . token !== "}" ;
219198 // callable_variable : https://github.com/php/php-src/blob/493524454d66adde84e00d249d607ecd540de99f/Zend/zend_language_parser.y#L1122
220- if ( this . token !== "]" ) {
199+ if ( isCallableVariable ) {
221200 offset = this . read_expr ( ) ;
222- this . expect ( "] ") && this . next ( ) ;
201+ this . expect ( isSquareBracket ? "]" : "} ") && this . next ( ) ;
223202 } else {
224203 this . next ( ) ;
225204 }
226205 }
227206 result = node ( result , offset ) ;
228207 break ;
208+ }
229209 case this . tok . T_DOUBLE_COLON :
230210 // @see https://github.com/glayzzle/php-parser/issues/107#issuecomment-354104574
231211 if (
0 commit comments