syntax error, unexpected identifier “%s”, expecting variable or “$”¶
Description¶
new works with objects, static properties and normal properties. It does not work with class constants, even if the constant is an object.
Example¶
<?php
class A {
const B = C;
}
const C = new A;
var_dump(new A::B);
?>
Literal Examples¶
syntax error, unexpected identifier “B”, expecting variable or “$”
Solutions¶
Store the constant in a variable, and
newthe variable.Get the class name with
get_classor::classand then, create the new object.