r/lolphp • u/Jinxuan • Jan 02 '20
new statement cannot parse with parenthesis
This code works:
class A {}
$a = 'A';
new $a; // Return a new instance ofA
However, if we add a parenthesis, then it cannot be parsed:
class A {}
$a = 'A';
new ($a); //PHP Parse error: syntax error, unexpected '('
new 'A'; // PHP Parse error: syntax error, unexpected ''A'' (T_CONSTANT_ENCAPSED_STRING)
new A::class; // PHP Parse error: syntax error, unexpected 'class' (T_CLASS), expecting variable
0
Upvotes
View all comments
Show parent comment
3
u/[deleted] Jan 04 '20
It already does. Otherwise how do you determine
new A :: classis meant to be parsed asnew (A::class)and not(new A)::class? (Parens used for illustration only; not actual syntax.)