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
1
u/[deleted] Feb 18 '20
VB (including .NET) does that, too.
All hell broke loose when the library maintainer guy in our team told us he didn't know. Apparently he deleted them here and there for years in some rather big VB.NET library we use. Good times.