-
-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathShortArrayTest.inc
More file actions
128 lines (88 loc) · 2.77 KB
/
ShortArrayTest.inc
File metadata and controls
128 lines (88 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/*
* Square brackets.
*/
/* testArrayAccess1 */
$var = $array[10];
$var = $array[++$y]/* testArrayAccess2 */[$x];
/* testArrayAssignment */
$array[] = $var;
/* testFunctionCallDereferencing */
$var = function_call()[$x];
/* testMethodCallDereferencing */
$var = $obj->function_call()[$x];
/* testStaticMethodCallDereferencing */
$var = ClassName::function_call()[$x];
/* testPropertyDereferencing */
$var = $obj->property[2];
/* testPropertyDereferencingWithInaccessibleName */
$var = $ref->{'ref-type'}[1];
/* testStaticPropertyDereferencing */
$var ClassName::$property[2];
/* testStringDereferencing */
$var = 'PHP'[1];
/* testStringDereferencingDoubleQuoted */
$var = "PHP"[$y];
/* testConstantDereferencing */
$var = MY_CONSTANT[1];
/* testClassConstantDereferencing */
$var ClassName::CONSTANT_NAME[2];
/* testMagicConstantDereferencing */
$var = __FILE__[0];
/* testArrayAccessCurlyBraces */
$var = $array{'key'}['key'];
/* testArrayLiteralDereferencing */
echo array(1, 2, 3)[0];
echo [1, 2, 3]/* testShortArrayLiteralDereferencing */[0];
/* testClassMemberDereferencingOnInstantiation1 */
(new foo)[0];
/* testClassMemberDereferencingOnInstantiation2 */
$a = (new Foo( array(1, array(4, 5), 3) ))[1][0];
/* testClassMemberDereferencingOnClone */
echo (clone $iterable)[20];
/* testNullsafeMethodCallDereferencing */
$var = $obj?->function_call()[$x];
/* testInterpolatedStringDereferencing */
$var = "PHP{$rocks}"[1];
/* testNewAnonClassNoParenthesesExpressionDereferencing */
$a = new class {}[0];
$a = new class (['value'])
/* testNewAnonClassParenthesesExpressionDereferencing */
{}[0];
/* testNewAnonClassExtendsExpressionDereferencing */
$a = new readonly class extends ArrayObject {}[0];
/* testNewAnonClassImplementsExpressionDereferencing */
$a = new class implements ArrayAccess {}[0];
/*
* Short array brackets.
*/
/* testShortArrayDeclarationEmpty */
$array = [];
/* testShortArrayDeclarationWithOneValue */
$array = [1];
/* testShortArrayDeclarationWithMultipleValues */
$array = [1, 2, 3];
/* testShortArrayDeclarationWithDereferencing */
echo [1, 2, 3][0];
/* testShortListDeclaration */
[ $a, $b ] = $array;
[ $a, $b, /* testNestedListDeclaration */, [$c, $d]] = $array;
/* testArrayWithinFunctionCall */
$var = functionCall([$x, $y]);
if ( true ) {
/* testShortListDeclarationAfterBracedControlStructure */
[ $a ] = [ 'hi' ];
}
if ( true )
/* testShortListDeclarationAfterNonBracedControlStructure */
[ $a ] = [ 'hi' ];
if ( true ) :
/* testShortListDeclarationAfterAlternativeControlStructure */
[ $a ] = [ 'hi' ];
endif;
class Foo extends ArrayObject {}
/* testShortListDeclarationAfterClassDeclaration */
[$a] = ['hi'];
/* testLiveCoding */
// Intentional parse error. This has to be the last test in the file.
$array = [