rfc:concatenation_precedence
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:concatenation_precedence [2019/03/28 09:57] – created bwoebi | rfc:concatenation_precedence [2020/08/01 23:54] (current) – RFC was implemented carusogabriel | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Change the precedence of the concatenation operator ====== | ====== PHP RFC: Change the precedence of the concatenation operator ====== | ||
- | * Version: | + | * Version: |
* Date: 2019-03-28 | * Date: 2019-03-28 | ||
* Author: Bob Weinand, bobwei9@hotmail.com | * Author: Bob Weinand, bobwei9@hotmail.com | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | It's been a long standing issue that an expression | + | It's been a long standing issue that an (unparenthesized) |
+ | |||
+ | <code php> | ||
+ | echo "sum: " . $a + $b; | ||
+ | |||
+ | // current behavior: evaluated | ||
+ | echo ("sum: " . $a) + $b; | ||
+ | |||
+ | // desired behavior: addition | ||
+ | echo "sum :" . ($a + $b); | ||
+ | </code> | ||
This RFC aims to change that behavior to be less error-prone and more intuitive. | This RFC aims to change that behavior to be less error-prone and more intuitive. | ||
Line 18: | Line 28: | ||
This is counter-intuitive though: you rarely want to add or subtract concatenated strings which in general are not numbers. However, given PHPs capability of seamlessly converting an integer to a string, concatenation of these values is desired. | This is counter-intuitive though: you rarely want to add or subtract concatenated strings which in general are not numbers. However, given PHPs capability of seamlessly converting an integer to a string, concatenation of these values is desired. | ||
- | Thus, the RFC proposes to give ' | + | Thus, the RFC proposes to give ' |
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | Every unparenthesized expression featuring an ' | + | Every unparenthesized expression featuring an ' |
While this is a subtle behavior change in that it will give different outputs without notice or warning, it is trivially possible to statically analyze the code and find all instances where this happens. As to my knowledge these occurrences are quite rare as it almost always is an error in the current form, rendering the impact minimal. | While this is a subtle behavior change in that it will give different outputs without notice or warning, it is trivially possible to statically analyze the code and find all instances where this happens. As to my knowledge these occurrences are quite rare as it almost always is an error in the current form, rendering the impact minimal. | ||
+ | |||
+ | As Nikita mentioned on the mailing list: http:// | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
- | The next 7.x (currently | + | PHP 8, with a deprecation notice in PHP 7.4 upon encountering an unparenthesized expression containing an ' |
- | Or, alternatively as a gentler upgrade, we may choose to fail hard in PHP 7.4, i.e. failing the compilation if an unparenthesized expression containing an ' | + | ===== Vote ===== |
- | ===== Proposed | + | Voting |
- | " | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
- | The RFC requires | + | <doodle title=" |
+ | * Yes | ||
+ | * No | ||
+ | </ | ||
===== Patch ===== | ===== Patch ===== | ||
- | The patch for the change itself is trivial, requiring small changes in the zend_ast.c and zend_language_parser.y to change the precendences. I'll add it later. | + | * https:// |
+ | * https:// |
rfc/concatenation_precedence.1553767075.txt.gz · Last modified: 2019/03/28 09:57 by bwoebi