syntax error, unexpected token “::”, expecting “,” or “;”

Description

The object operator :: is used in an expression, where it is not expected.

Here, it is a global variable statement. Such statement were possible in PHP 5 and older, but are not valid anymore since PHP 7.0. Then, PHP would use the content of the property as the name of the global variable.

The same error is emitted with static variables, with the :: and the -> operators.

Example

<?php

global $object::$property;

static $object::$property;

?>

Solutions

  • Remove the property or method call from the global instruction.