@@ -353,9 +353,20 @@ module.exports = {
353
353
if ( this . is ( 'VARIABLE' ) ) {
354
354
var result = this . node ( ) ;
355
355
expr = this . read_variable ( false , false , false ) ;
356
+
357
+ // https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L877
358
+ // should accept only a variable
359
+ var isConst = (
360
+ expr . kind === 'constref' || (
361
+ expr . kind === 'staticlookup' &&
362
+ expr . offset . kind === 'constref'
363
+ )
364
+ ) ;
365
+
356
366
// VARIABLES SPECIFIC OPERATIONS
357
367
switch ( this . token ) {
358
368
case '=' :
369
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
359
370
var right ;
360
371
if ( this . next ( ) . token == '&' ) {
361
372
if ( this . next ( ) . token === this . tok . T_NEW ) {
@@ -370,45 +381,59 @@ module.exports = {
370
381
371
382
// operations :
372
383
case this . tok . T_PLUS_EQUAL :
384
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
373
385
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '+=' ) ;
374
386
375
387
case this . tok . T_MINUS_EQUAL :
388
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
376
389
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '-=' ) ;
377
390
378
391
case this . tok . T_MUL_EQUAL :
392
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
379
393
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '*=' ) ;
380
394
381
395
case this . tok . T_POW_EQUAL :
396
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
382
397
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '**=' ) ;
383
398
384
399
case this . tok . T_DIV_EQUAL :
400
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
385
401
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '/=' ) ;
386
402
387
403
case this . tok . T_CONCAT_EQUAL :
404
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
388
405
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '.=' ) ;
389
406
390
407
case this . tok . T_MOD_EQUAL :
408
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
391
409
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '%=' ) ;
392
410
393
411
case this . tok . T_AND_EQUAL :
412
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
394
413
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '&=' ) ;
395
414
396
415
case this . tok . T_OR_EQUAL :
416
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
397
417
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '|=' ) ;
398
418
399
419
case this . tok . T_XOR_EQUAL :
420
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
400
421
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '^=' ) ;
401
422
402
423
case this . tok . T_SL_EQUAL :
424
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
403
425
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '<<=' ) ;
404
426
405
427
case this . tok . T_SR_EQUAL :
428
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
406
429
return result ( 'assign' , expr , this . next ( ) . read_expr ( ) , '>>=' ) ;
407
430
408
431
case this . tok . T_INC :
432
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
409
433
this . next ( ) ;
410
434
return result ( 'post' , '+' , expr ) ;
411
435
case this . tok . T_DEC :
436
+ if ( isConst ) this . error ( 'VARIABLE' ) ;
412
437
this . next ( ) ;
413
438
return result ( 'post' , '-' , expr ) ;
414
439
}
0 commit comments