Remove support for alternative array syntax in PHP 8 parser

We cannot support both this syntax and property hooks. Drop
support for the alternative syntax in the PHP 8 parser. The
PHP 7 parser still supports it.
This commit is contained in:
Nikita Popov 2024-07-19 22:21:17 +02:00
parent fadccead52
commit beba9c528f
11 changed files with 996 additions and 858 deletions

View File

@ -1242,7 +1242,9 @@ callable_expr:
callable_variable: callable_variable:
simple_variable simple_variable
| array_object_dereferenceable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } | array_object_dereferenceable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
#if PHP7
| array_object_dereferenceable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } | array_object_dereferenceable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
#endif
| function_call | function_call
| array_object_dereferenceable T_OBJECT_OPERATOR property_name argument_list | array_object_dereferenceable T_OBJECT_OPERATOR property_name argument_list
{ $$ = Expr\MethodCall[$1, $3, $4]; } { $$ = Expr\MethodCall[$1, $3, $4]; }
@ -1284,7 +1286,9 @@ static_member:
new_variable: new_variable:
simple_variable simple_variable
| new_variable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; } | new_variable '[' optional_expr ']' { $$ = Expr\ArrayDimFetch[$1, $3]; }
#if PHP7
| new_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; } | new_variable '{' expr '}' { $$ = Expr\ArrayDimFetch[$1, $3]; }
#endif
| new_variable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; } | new_variable T_OBJECT_OPERATOR property_name { $$ = Expr\PropertyFetch[$1, $3]; }
| new_variable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; } | new_variable T_NULLSAFE_OBJECT_OPERATOR property_name { $$ = Expr\NullsafePropertyFetch[$1, $3]; }
| class_name T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name | class_name T_PAAMAYIM_NEKUDOTAYIM static_member_prop_name

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,335 @@
Alternative array syntax
-----
<?php
$a{'b'};
$a{'b'}();
$a->b{'c'};
$a->b(){'c'};
A::$b{'c'};
A{0};
A::B{0};
new $array{'className'};
new $a->b{'c'}();
-----
!!version=7.4
array(
0: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
)
1: Stmt_Expression(
expr: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
args: array(
)
)
)
2: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
)
3: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
args: array(
)
)
dim: Scalar_String(
value: c
)
)
)
4: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
name: A
)
name: VarLikeIdentifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
)
5: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_ConstFetch(
name: Name(
name: A
)
)
dim: Scalar_Int(
value: 0
)
)
)
6: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
name: A
)
name: Identifier(
name: B
)
)
dim: Scalar_Int(
value: 0
)
)
)
7: Stmt_Expression(
expr: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
)
8: Stmt_Expression(
expr: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
)
)
-----
<?php
$a{'b'};
$a{'b'}();
$a->b{'c'};
$a->b(){'c'};
A::$b{'c'};
A{0};
A::B{0};
new $array{'className'};
new $a->b{'c'}();
-----
Syntax error, unexpected '{' from 3:3 to 3:3
Syntax error, unexpected '{' from 4:3 to 4:3
Syntax error, unexpected '{' from 5:6 to 5:6
Syntax error, unexpected '{' from 6:8 to 6:8
Syntax error, unexpected '{' from 7:6 to 7:6
Syntax error, unexpected '{' from 8:2 to 8:2
Syntax error, unexpected '{' from 9:5 to 9:5
Syntax error, unexpected '{' from 10:11 to 10:11
Syntax error, unexpected '{' from 11:10 to 11:10
array(
0: Stmt_Expression(
expr: Expr_Variable(
name: a
)
)
1: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: b
)
)
)
)
2: Stmt_Expression(
expr: Expr_Variable(
name: a
)
)
3: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: b
)
)
)
)
4: Stmt_Expression(
expr: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
)
5: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: c
)
)
)
)
6: Stmt_Expression(
expr: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
args: array(
)
)
)
7: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: c
)
)
)
)
8: Stmt_Expression(
expr: Expr_StaticPropertyFetch(
class: Name(
name: A
)
name: VarLikeIdentifier(
name: b
)
)
)
9: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: c
)
)
)
)
10: Stmt_Expression(
expr: Expr_ConstFetch(
name: Name(
name: A
)
)
)
11: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_Int(
value: 0
)
)
)
)
12: Stmt_Expression(
expr: Expr_ClassConstFetch(
class: Name(
name: A
)
name: Identifier(
name: B
)
)
)
13: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_Int(
value: 0
)
)
)
)
14: Stmt_Expression(
expr: Expr_New(
class: Expr_Variable(
name: array
)
args: array(
)
)
)
15: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: className
)
)
)
)
16: Stmt_Expression(
expr: Expr_New(
class: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
args: array(
)
)
)
17: Stmt_Block(
stmts: array(
0: Stmt_Expression(
expr: Scalar_String(
value: c
)
)
)
)
)

View File

@ -9,7 +9,6 @@ ${'a'}();
$$a(); $$a();
$$$a(); $$$a();
$a['b'](); $a['b']();
$a{'b'}();
$a->b['c'](); $a->b['c']();
// array dereferencing // array dereferencing
@ -87,20 +86,6 @@ array(
) )
) )
6: Stmt_Expression( 6: Stmt_Expression(
expr: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
args: array(
)
)
)
7: Stmt_Expression(
expr: Expr_FuncCall( expr: Expr_FuncCall(
name: Expr_ArrayDimFetch( name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch( var: Expr_PropertyFetch(
@ -119,7 +104,7 @@ array(
) )
) )
) )
8: Stmt_Expression( 7: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Expr_FuncCall( var: Expr_FuncCall(
name: Name( name: Name(

View File

@ -5,7 +5,6 @@ Object access
// property fetch variations // property fetch variations
$a->b; $a->b;
$a->b['c']; $a->b['c'];
$a->b{'c'};
// method call variations // method call variations
$a->b(); $a->b();
@ -15,7 +14,6 @@ $a->$b['c']();
// array dereferencing // array dereferencing
$a->b()['c']; $a->b()['c'];
$a->b(){'c'};
----- -----
array( array(
0: Stmt_Expression( 0: Stmt_Expression(
@ -47,21 +45,6 @@ array(
) )
) )
2: Stmt_Expression( 2: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
)
3: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_Variable( var: Expr_Variable(
name: a name: a
@ -76,7 +59,7 @@ array(
0: // method call variations 0: // method call variations
) )
) )
4: Stmt_Expression( 3: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_Variable( var: Expr_Variable(
name: a name: a
@ -88,7 +71,7 @@ array(
) )
) )
) )
5: Stmt_Expression( 4: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_Variable( var: Expr_Variable(
name: a name: a
@ -100,7 +83,7 @@ array(
) )
) )
) )
6: Stmt_Expression( 5: Stmt_Expression(
expr: Expr_FuncCall( expr: Expr_FuncCall(
name: Expr_ArrayDimFetch( name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch( var: Expr_PropertyFetch(
@ -119,7 +102,7 @@ array(
) )
) )
) )
7: Stmt_Expression( 6: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Expr_MethodCall( var: Expr_MethodCall(
var: Expr_Variable( var: Expr_Variable(
@ -139,21 +122,4 @@ array(
0: // array dereferencing 0: // array dereferencing
) )
) )
8: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
args: array(
)
)
dim: Scalar_String(
value: c
)
)
)
) )

View File

@ -5,7 +5,6 @@ Simple array access
$a['b']; $a['b'];
$a['b']['c']; $a['b']['c'];
$a[] = $b; $a[] = $b;
$a{'b'};
${$a}['b']; ${$a}['b'];
----- -----
array( array(
@ -48,16 +47,6 @@ array(
) )
) )
3: Stmt_Expression( 3: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
)
4: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Expr_Variable( var: Expr_Variable(
name: Expr_Variable( name: Expr_Variable(

View File

@ -9,7 +9,6 @@ A::${'b'};
// array access // array access
A::$b['c']; A::$b['c'];
A::$b{'c'};
// class name variations can be found in staticCall.test // class name variations can be found in staticCall.test
----- -----
@ -65,22 +64,7 @@ array(
0: // array access 0: // array access
) )
) )
4: Stmt_Expression( 4: Stmt_Nop(
expr: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
name: A
)
name: VarLikeIdentifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
)
5: Stmt_Nop(
comments: array( comments: array(
0: // class name variations can be found in staticCall.test 0: // class name variations can be found in staticCall.test
) )

View File

@ -13,7 +13,6 @@ new A::$b();
new $a->b(); new $a->b();
new $a->b->c(); new $a->b->c();
new $a->b['c'](); new $a->b['c']();
new $a->b{'c'}();
// test regression introduces by new dereferencing syntax // test regression introduces by new dereferencing syntax
(new A); (new A);
@ -141,25 +140,6 @@ array(
) )
) )
8: Stmt_Expression( 8: Stmt_Expression(
expr: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: Identifier(
name: b
)
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
)
9: Stmt_Expression(
expr: Expr_New( expr: Expr_New(
class: Name( class: Name(
name: A name: A

View File

@ -8,7 +8,6 @@ new A()::FOO;
new A()::foo(); new A()::foo();
new A()::$foo; new A()::$foo;
new A()[0]; new A()[0];
new A(){0};
new A()(); new A()();
new class {}->foo; new class {}->foo;
@ -17,7 +16,6 @@ new class {}::FOO;
new class {}::foo(); new class {}::foo();
new class {}::$foo; new class {}::$foo;
new class {}[0]; new class {}[0];
new class {}{0};
new class {}(); new class {}();
----- -----
array( array(
@ -110,20 +108,6 @@ array(
) )
) )
6: Stmt_Expression( 6: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
name: A
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
7: Stmt_Expression(
expr: Expr_FuncCall( expr: Expr_FuncCall(
name: Expr_New( name: Expr_New(
class: Name( class: Name(
@ -136,7 +120,7 @@ array(
) )
) )
) )
8: Stmt_Expression( 7: Stmt_Expression(
expr: Expr_PropertyFetch( expr: Expr_PropertyFetch(
var: Expr_New( var: Expr_New(
class: Stmt_Class( class: Stmt_Class(
@ -158,7 +142,7 @@ array(
) )
) )
) )
9: Stmt_Expression( 8: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_New( var: Expr_New(
class: Stmt_Class( class: Stmt_Class(
@ -182,7 +166,7 @@ array(
) )
) )
) )
10: Stmt_Expression( 9: Stmt_Expression(
expr: Expr_ClassConstFetch( expr: Expr_ClassConstFetch(
class: Expr_New( class: Expr_New(
class: Stmt_Class( class: Stmt_Class(
@ -204,7 +188,7 @@ array(
) )
) )
) )
11: Stmt_Expression( 10: Stmt_Expression(
expr: Expr_StaticCall( expr: Expr_StaticCall(
class: Expr_New( class: Expr_New(
class: Stmt_Class( class: Stmt_Class(
@ -228,7 +212,7 @@ array(
) )
) )
) )
12: Stmt_Expression( 11: Stmt_Expression(
expr: Expr_StaticPropertyFetch( expr: Expr_StaticPropertyFetch(
class: Expr_New( class: Expr_New(
class: Stmt_Class( class: Stmt_Class(
@ -250,51 +234,29 @@ array(
) )
) )
) )
12: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
13: Stmt_Expression( 13: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
14: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_New(
class: Stmt_Class(
attrGroups: array(
)
flags: 0
name: null
extends: null
implements: array(
)
stmts: array(
)
)
args: array(
)
)
dim: Scalar_Int(
value: 0
)
)
)
15: Stmt_Expression(
expr: Expr_FuncCall( expr: Expr_FuncCall(
name: Expr_New( name: Expr_New(
class: Stmt_Class( class: Stmt_Class(

View File

@ -6,11 +6,9 @@ A->length;
A->length(); A->length();
A[0]; A[0];
A[0][1][2]; A[0][1][2];
A{0};
A::B[0]; A::B[0];
A::B[0][1][2]; A::B[0][1][2];
A::B{0};
A::B->length; A::B->length;
A::B->length(); A::B->length();
A::B::C; A::B::C;
@ -83,18 +81,6 @@ array(
) )
) )
4: Stmt_Expression( 4: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_ConstFetch(
name: Name(
name: A
)
)
dim: Scalar_Int(
value: 0
)
)
)
5: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch( var: Expr_ClassConstFetch(
class: Name( class: Name(
@ -109,7 +95,7 @@ array(
) )
) )
) )
6: Stmt_Expression( 5: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch( var: Expr_ArrayDimFetch(
@ -134,22 +120,7 @@ array(
) )
) )
) )
7: Stmt_Expression( 6: Stmt_Expression(
expr: Expr_ArrayDimFetch(
var: Expr_ClassConstFetch(
class: Name(
name: A
)
name: Identifier(
name: B
)
)
dim: Scalar_Int(
value: 0
)
)
)
8: Stmt_Expression(
expr: Expr_PropertyFetch( expr: Expr_PropertyFetch(
var: Expr_ClassConstFetch( var: Expr_ClassConstFetch(
class: Name( class: Name(
@ -164,7 +135,7 @@ array(
) )
) )
) )
9: Stmt_Expression( 7: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_ClassConstFetch( var: Expr_ClassConstFetch(
class: Name( class: Name(
@ -181,7 +152,7 @@ array(
) )
) )
) )
10: Stmt_Expression( 8: Stmt_Expression(
expr: Expr_ClassConstFetch( expr: Expr_ClassConstFetch(
class: Expr_ClassConstFetch( class: Expr_ClassConstFetch(
class: Name( class: Name(
@ -196,7 +167,7 @@ array(
) )
) )
) )
11: Stmt_Expression( 9: Stmt_Expression(
expr: Expr_StaticPropertyFetch( expr: Expr_StaticPropertyFetch(
class: Expr_ClassConstFetch( class: Expr_ClassConstFetch(
class: Name( class: Name(
@ -211,7 +182,7 @@ array(
) )
) )
) )
12: Stmt_Expression( 10: Stmt_Expression(
expr: Expr_StaticCall( expr: Expr_StaticCall(
class: Expr_ClassConstFetch( class: Expr_ClassConstFetch(
class: Name( class: Name(
@ -228,7 +199,7 @@ array(
) )
) )
) )
13: Stmt_Expression( 11: Stmt_Expression(
expr: Expr_ArrayDimFetch( expr: Expr_ArrayDimFetch(
var: Scalar_MagicConst_Function( var: Scalar_MagicConst_Function(
) )
@ -237,7 +208,7 @@ array(
) )
) )
) )
14: Stmt_Expression( 12: Stmt_Expression(
expr: Expr_PropertyFetch( expr: Expr_PropertyFetch(
var: Scalar_MagicConst_Function( var: Scalar_MagicConst_Function(
) )
@ -246,7 +217,7 @@ array(
) )
) )
) )
15: Stmt_Expression( 13: Stmt_Expression(
expr: Expr_MethodCall( expr: Expr_MethodCall(
var: Expr_ConstFetch( var: Expr_ConstFetch(
name: Name( name: Name(

View File

@ -3,7 +3,6 @@ UVS new expressions
<?php <?php
new $className; new $className;
new $array['className']; new $array['className'];
new $array{'className'};
new $obj->className; new $obj->className;
new Test::$className; new Test::$className;
new $test::$className; new $test::$className;
@ -34,20 +33,6 @@ array(
) )
) )
2: Stmt_Expression( 2: Stmt_Expression(
expr: Expr_New(
class: Expr_ArrayDimFetch(
var: Expr_Variable(
name: array
)
dim: Scalar_String(
value: className
)
)
args: array(
)
)
)
3: Stmt_Expression(
expr: Expr_New( expr: Expr_New(
class: Expr_PropertyFetch( class: Expr_PropertyFetch(
var: Expr_Variable( var: Expr_Variable(
@ -61,7 +46,7 @@ array(
) )
) )
) )
4: Stmt_Expression( 3: Stmt_Expression(
expr: Expr_New( expr: Expr_New(
class: Expr_StaticPropertyFetch( class: Expr_StaticPropertyFetch(
class: Name( class: Name(
@ -75,7 +60,7 @@ array(
) )
) )
) )
5: Stmt_Expression( 4: Stmt_Expression(
expr: Expr_New( expr: Expr_New(
class: Expr_StaticPropertyFetch( class: Expr_StaticPropertyFetch(
class: Expr_Variable( class: Expr_Variable(
@ -89,7 +74,7 @@ array(
) )
) )
) )
6: Stmt_Expression( 5: Stmt_Expression(
expr: Expr_New( expr: Expr_New(
class: Expr_StaticPropertyFetch( class: Expr_StaticPropertyFetch(
class: Expr_PropertyFetch( class: Expr_PropertyFetch(