syntax error, unexpected ‘::’ (T_PAAMAYIM_NEKUDOTAYIM), expecting ‘;’ or ‘,’¶
Description¶
Using the static class syntax directly on an interpolated string was not possible until PHP 8.0. Until then, it reported a syntax error.
Example¶
<?php
class Bar {
static function foo() {}
static $property = 3;
const C = 4;
}
$a = "ar";
echo "B$a"::foo();
echo "B$a"::$property;
echo "B$a"::C;
?>
Solutions¶
Upgrade to PHP 8.0 or more recent.
Store the class name in a variable, and use that variable instead of the direct string.