syntax error, unexpected token “,”, expecting variable

Description

This error is reported when a list of variable is expected after a keyword.

This is the case with the visibility options public, protected and private, which expect a list of property names.

This is also the case with global and static, which are declaring global and static variables.

Generally speaking, there can be no two successive commas in an expression, except with the list() keyword.

Example

<?php

class X {
     public $a, , $c;

     public function foo() {
         static $a, , $c;
     }
}
?>

Solutions

  • Remove the extra comma.

  • Fill the empty slot with a variable.