-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
RemovedDollarBraceStringEmbedsUnitTest.1.inc
90 lines (72 loc) · 1.83 KB
/
RemovedDollarBraceStringEmbedsUnitTest.1.inc
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
<?php
/*
* Embedded variables which are supported cross-version.
*/
// Type 1: directly embedding variables.
echo "$foo";
echo "$$foo";
echo "$foo[bar]";
echo "$foo->bar";
$text = "some text $var some text";
$heredoc = <<<EOD
some text $var some text
EOD;
// Type 2: Braces around the variable/expression.
echo "{$foo}";
echo "{$$foo}";
echo "{$foo['bar']}";
echo "{$foo->bar}";
echo "{$foo->bar()}";
echo "{$foo['bar']->baz()()}";
echo "{${$bar}}";
echo "{$foo()}";
echo "{${$object->getMethod()}}"
$text = "some text {$var} some text";
$heredoc = <<<"EOD"
some text {$var} some text
EOD;
/*
* Not our target.
*/
// Ordinary variable variables outside strings.
$foo = ${'bar'};
// Heredoc without embeds.
echo <<<EOD
Some text
EOD;
// Not actually interpolated - $ is escaped. The second $foo is to force T_DOUBLE_QUOTED_STRING tokenization.
echo "\${foo} and $foo";
echo "\${foo[\"bar\"]} and $foo";
echo "$\{foo} and $foo";
/*
* PHP 8.2: deprecated forms of embedding variables.
*/
// Type 3: Braces after the dollar sign.
echo "${foo}";
echo "${foo['bar']}";
$text = "some text ${foo} some ${text}";
$heredoc = <<<EOD
some text ${foo} some text
EOD;
echo "\\${foo}"; // Not actually escaped, the backslash escapes the backslash, not the dollar sign.
// Type 4: Variable variables.
echo "${$bar}";
echo "${(foo)}";
echo "${foo->bar}";
echo "${$object->getMethod()}"
$text = "some text ${(foo)} some text";
echo "${substr('laruence', 0, 2)}";
echo "${foo["${bar}"]}";
echo "${foo["${bar['baz']}"]}";
echo "${foo->{$baz}}";
echo "${foo->{${'a'}}}";
echo "${foo->{"${'a'}"}}";
// Verify correct handling of stack pointers in multi-token code.
$text = "Line without embed
some text ${foo["${bar}"]} some text
some text ${foo["${bar['baz']}"]} some text
some text ${foo->{${'a'}}} some text
";
$heredoc = <<<"EOD"
some text ${(foo)} some text
EOD;