rfc:deprecate_dollar_brace_string_interpolation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
rfc:deprecate_dollar_brace_string_interpolation [2021/03/13 14:25] – Create RFC ilutovrfc:deprecate_dollar_brace_string_interpolation [2021/03/13 14:28] – Fix option ilutov
Line 20: Line 20:
 ===== Status quo ===== ===== Status quo =====
  
-====== Options 1, 2 and 3 ======+==== Options 1, 2 and 3 ====
  
 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. 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.
Line 48: Line 48:
 </code> </code>
  
-Only syntax allows calling methods.+Only syntax allows calling methods.
  
 <code php> <code php>
Line 61: Line 61:
 </code> </code>
  
-Only syntax allows chaining all of the above.+Only syntax allows chaining all of the above.
  
 <code php> <code php>
Line 74: Line 74:
 </code> </code>
  
-====== Option 4 ======+==== Option 4 ====
  
 PHP has a feature called [[https://www.php.net/manual/en/language.variables.variable.php|Variable variables]]. It allows you to get a variable by name. The name can be a string stored in another variable. PHP has a feature called [[https://www.php.net/manual/en/language.variables.variable.php|Variable variables]]. It allows you to get a variable by name. The name can be a string stored in another variable.
Line 108: Line 108:
 The braces switch from option 3 to 4 because braces are not allowed in option 3. This means ''foo'' is no longer interpreted as a variable but as a constant, and option 4 will then try to find a local variable by the name of that constant. This is incredibly unintuitive. The braces switch from option 3 to 4 because braces are not allowed in option 3. This means ''foo'' is no longer interpreted as a variable but as a constant, and option 4 will then try to find a local variable by the name of that constant. This is incredibly unintuitive.
  
-====== Conclusion ======+===== Conclusion =====
  
 Options 1, 2 and 3 all try to achieve the same thing. Option 1 is less powerful than option 2 but it is shorter so both have some justification for existing. Option 3 is less powerful than both while not being shorter than any of them. Option 4 is not commonly useful. Option 3 and 4 clash syntax-wise. Options 1, 2 and 3 all try to achieve the same thing. Option 1 is less powerful than option 2 but it is shorter so both have some justification for existing. Option 3 is less powerful than both while not being shorter than any of them. Option 4 is not commonly useful. Option 3 and 4 clash syntax-wise.
rfc/deprecate_dollar_brace_string_interpolation.txt · Last modified: 2022/05/05 08:17 by ilutov