rfc:deprecate_dollar_brace_string_interpolation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
rfc:deprecate_dollar_brace_string_interpolation [2021/03/13 14:30] – Adjust voting title ilutov | rfc:deprecate_dollar_brace_string_interpolation [2021/03/13 18:22] – Overhaul language to make it more compelling. crell | ||
---|---|---|---|
Line 16: | Line 16: | ||
4. Dynamic variable lookup (" | 4. Dynamic variable lookup (" | ||
- | Unfortunately, | + | All of these have their pros and cons, but in practice |
+ | |||
+ | This RFC proposes to deprecate options 3 and 4 in PHP 8.1 and remove them in PHP 9.0. That leaves only two string interpolation options: direct (simple variable only) and powerful (the one that does the most now). | ||
===== Status quo ===== | ===== Status quo ===== | ||
- | ==== Options 1, 2 and 3 ==== | + | The first issue is that all four options support different subsets of syntax. |
- | Options 1, 2 and 3 all roughty try to do they same thing: They embed a local variable in a string, sometimes allowing to call a method or access an array offset on that variable. All of these examples are equivalent. | + | ==== Simple variable interpolation ==== |
+ | |||
+ | Options 1, 2, and 3 support embedding basic variables. | ||
<code php> | <code php> | ||
$foo = ' | $foo = ' | ||
+ | |||
var_dump(" | var_dump(" | ||
var_dump(" | var_dump(" | ||
Line 31: | Line 36: | ||
</ | </ | ||
- | All of the three options | + | ==== Array-offset interpolation ==== |
+ | |||
+ | Options 1, 2, and 3 allow accessing an array offset. Unfortunately, | ||
<code php> | <code php> | ||
$foo = [' | $foo = [' | ||
var_dump(" | var_dump(" | ||
+ | |||
var_dump(" | var_dump(" | ||
var_dump(" | var_dump(" | ||
</ | </ | ||
+ | |||
+ | ==== Object property interpolation ==== | ||
Only syntax 1 and 2 allow accessing properties. | Only syntax 1 and 2 allow accessing properties. | ||
Line 44: | Line 54: | ||
<code php> | <code php> | ||
$foo = (object) [' | $foo = (object) [' | ||
+ | |||
var_dump(" | var_dump(" | ||
var_dump(" | var_dump(" | ||
</ | </ | ||
+ | |||
+ | ==== Metehod call interpolation ==== | ||
Only syntax 2 allows calling methods. | Only syntax 2 allows calling methods. | ||
Line 60: | Line 73: | ||
var_dump(" | var_dump(" | ||
</ | </ | ||
+ | |||
+ | ==== Compound interpolation ==== | ||
Only syntax 2 allows chaining all of the above. | Only syntax 2 allows chaining all of the above. | ||
Line 107: | Line 122: | ||
The braces switch from option 3 to 4 because braces are not allowed in option 3. This means '' | The braces switch from option 3 to 4 because braces are not allowed in option 3. This means '' | ||
+ | |||
+ | ==== Comparison to other languages ==== | ||
+ | |||
+ | A number of other languages use '' | ||
===== Conclusion ===== | ===== Conclusion ===== | ||
- | Options | + | Option |
+ | |||
+ | Option 2 offers the most robust syntax currently supported, and is widely used. | ||
+ | |||
+ | Option 3 offers a subset of the functionality of option 2, and is not widely used. | ||
+ | |||
+ | Option 4 offers functionality that is rarely if ever useful, and easily confused with option 3. | ||
For all of the reasons above this RFC proposes to deprecate option 3 and 4 in PHP 8.1 and remove them in PHP 9. | For all of the reasons above this RFC proposes to deprecate option 3 and 4 in PHP 8.1 and remove them in PHP 9. |
rfc/deprecate_dollar_brace_string_interpolation.txt · Last modified: 2022/05/05 08:17 by ilutov