rfc:arbitrary_string_interpolation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:arbitrary_string_interpolation [2022/03/17 18:56] – ilutov | rfc:arbitrary_string_interpolation [2022/06/25 21:47] (current) – Move to wirthdrawn ilutov | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2022-03-17 | * Date: 2022-03-17 | ||
* Author: Ilija Tovilo, tovilo.ilija@gmail.com | * Author: Ilija Tovilo, tovilo.ilija@gmail.com | ||
- | * Status: | + | * Status: |
* Target Version: PHP 8.2 | * Target Version: PHP 8.2 | ||
- | * Implementation: | + | * Implementation: |
===== Proposal ===== | ===== Proposal ===== | ||
Line 11: | Line 11: | ||
PHP has four types of string interpolation. The two most common forms are ''" | PHP has four types of string interpolation. The two most common forms are ''" | ||
- | All the current forms of string interpolation are limited to variables or variable chains (array access, properties, method calls, etc). This probably covers | + | All the current forms of string interpolation are limited to variables or variable chains (array access, properties, method calls, etc). This probably covers |
* Function calls | * Function calls | ||
* Constants | * Constants | ||
* Class constants | * Class constants | ||
- | * Statis | + | * Static |
<code php> | <code php> | ||
Line 38: | Line 38: | ||
</ | </ | ||
- | The proposed syntax works in double quoted strings (''""'' | + | The proposed syntax works in all cases where existing string interpolation is allowed, namely |
===== Motivation ===== | ===== Motivation ===== | ||
Line 44: | Line 44: | ||
Of course, this can already be achieved in two other ways: | Of course, this can already be achieved in two other ways: | ||
- | | + | |
- | | + | |
Creating local variables is not a terrible option. It does pollute the variable symbol table a bit and it requires more visual jumping to see what value is being embedded. | Creating local variables is not a terrible option. It does pollute the variable symbol table a bit and it requires more visual jumping to see what value is being embedded. | ||
Line 60: | Line 60: | ||
===== Syntax choice ===== | ===== Syntax choice ===== | ||
- | The primary advantage of the syntax ''" | + | The primary advantage of the syntax ''" |
+ | |||
+ | A different syntax could be chosen with a given BC break. | ||
+ | |||
+ | <code php> | ||
+ | echo "Hello # | ||
+ | </ | ||
+ | |||
+ | This could be mitigated by adding a prefix to the string itself. | ||
+ | |||
+ | <code php> | ||
+ | echo $" | ||
+ | </ | ||
+ | |||
+ | I think this is unfortunate because: | ||
+ | |||
+ | * Converting an existing string to '' | ||
+ | * The prefix will need to work for all existing string types that allow interpolation | ||
===== Escaping ===== | ===== Escaping ===== | ||
Line 86: | Line 103: | ||
None | None | ||
+ | |||
+ | ===== Comparison to other languages ===== | ||
+ | |||
+ | Most modern languages have string interpolation that allow arbitrary expressions. | ||
+ | |||
+ | ^ Language | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | | [[http:// | ||
+ | | [[https:// | ||
+ | | [[https:// | ||
+ | |||
+ | ===== Credits ===== | ||
+ | |||
+ | Credits to Rowan Tommins (IMSoP) for the syntax suggestion and comparison to other languges. | ||
===== Vote ===== | ===== Vote ===== |
rfc/arbitrary_string_interpolation.1647543371.txt.gz · Last modified: 2022/03/17 18:56 by ilutov