rfc:chaining_comparison
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:chaining_comparison [2016/12/22 16:22] – bp1222 | rfc:chaining_comparison [2021/03/27 14:58] (current) – Move to inactive ilutov | ||
---|---|---|---|
Line 4: | Line 4: | ||
* Author: David Walker (dave@mudsite.com) | * Author: David Walker (dave@mudsite.com) | ||
* Author: Richard Fussenegger (php@fleshgrinder.com) | * Author: Richard Fussenegger (php@fleshgrinder.com) | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes a syntax change to allow the chaining together of comparison and equality operations '' | + | This RFC proposes a syntax change to allow arbitrary |
<file php> | <file php> | ||
Line 22: | Line 22: | ||
/* | /* | ||
- | * To allow this to be functionally | + | * To be functionally |
*/ | */ | ||
if (0 < $a < 100) { | if (0 < $a < 100) { | ||
Line 31: | Line 31: | ||
===== Proposal ===== | ===== Proposal ===== | ||
Proposals herein will contain a dump of relevant AST (php-ast) nodes and OPCodes (vld) to better visualize the compilation, | Proposals herein will contain a dump of relevant AST (php-ast) nodes and OPCodes (vld) to better visualize the compilation, | ||
+ | |||
==== Comparison Chaining ==== | ==== Comparison Chaining ==== | ||
- | The proposal creates a new AST operation type '' | + | The proposal creates a new AST operation type '' |
<file php> | <file php> | ||
Line 117: | Line 118: | ||
*/ | */ | ||
</ | </ | ||
+ | |||
+ | ==== False Short Circuiting ==== | ||
+ | In doing this compilation we can ensure short cutting of righter operations if the left sides have evaluated to false. | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 181: | Line 185: | ||
var_dump(1 < 2 == 3); | var_dump(1 < 2 == 3); | ||
/* | /* | ||
- | * 1 < 2 == 3 := true == 3 := true | + | |
*/ | */ | ||
Line 191: | Line 195: | ||
var_dump(1 < 2 == (3 == 4)); | var_dump(1 < 2 == (3 == 4)); | ||
/* | /* | ||
- | * 1 < 2 == (3 == 4) := true == false := false | + | |
*/ | */ | ||
</ | </ | ||
Line 205: | Line 209: | ||
var_dump(1 < 2 == 3); | var_dump(1 < 2 == 3); | ||
/* | /* | ||
- | * 1 < 2 == 3 := true == 3 := true | + | |
*/ | */ | ||
var_dump(1 < 2 == 3 == 4); | var_dump(1 < 2 == 3 == 4); | ||
/* | /* | ||
- | * 1 < 2 == 3 == 4 := (true == 3) == 4 := true == 4 := true | + | |
*/ | */ | ||
var_dump(1 < 2 == (3 == 4)); | var_dump(1 < 2 == (3 == 4)); | ||
/* | /* | ||
- | * 1 < 2 == (3 == 4) := true == false := false | + | |
*/ | */ | ||
</ | </ | ||
Line 229: | Line 233: | ||
var_dump(1 < 2 == 3); | var_dump(1 < 2 == 3); | ||
/* | /* | ||
- | * 1 < 2 == 3 := true == 3 := true | + | |
*/ | */ | ||
var_dump(1 < 2 == 3 == 4); | var_dump(1 < 2 == 3 == 4); | ||
/* | /* | ||
- | * 1 < 2 == 3 == 4 := (true == 3) == 4 := true == 4 := true | + | |
*/ | */ | ||
var_dump(1 < 2 == (3 == 4)); | var_dump(1 < 2 == (3 == 4)); | ||
/* | /* | ||
- | * 1 < 2 == (3 == 4) := true == false := false | + | |
*/ | */ | ||
</ | </ | ||
If the first example in this last one looks a little odd, it's because it is. We do design for short-cutting of a long expression when a fault is found to prevent further execution much like you have in '' | If the first example in this last one looks a little odd, it's because it is. We do design for short-cutting of a long expression when a fault is found to prevent further execution much like you have in '' | ||
+ | |||
+ | Although allow right-recursion of equality operations does itself introduce some slightly odd syntax like: | ||
+ | <file php> | ||
+ | <?php | ||
+ | /* | ||
+ | * Right chained comparison syntax | ||
+ | */ | ||
+ | var_dump(1 < (2 == 2)); // bool(false) | ||
+ | |||
+ | /* | ||
+ | * Is Functionally identical to PHP 7.1's allowed syntax | ||
+ | */ | ||
+ | var_dump(1 < (2 <= 2)); // bool(false) | ||
+ | </ | ||
+ | Since we don't chain together the right/left node of an equality operator, this is functionally identical to PHP 7.1's allowed syntax. | ||
+ | |||
+ | |||
+ | As we can see right-recursive comparison operations do have numerous caveats and oddities. | ||
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
Line 252: | Line 274: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | Implementation | + | Working |
- | + | ||
- | Implementation #2: comparisons and equality evaluated together: https:// | + | |
Will need eyes of those more familiar with AST/VM to review. | Will need eyes of those more familiar with AST/VM to review. | ||
- | |||
- | For changes affecting the core language, you should also provide a patch for the language specification. | ||
===== Implementation ===== | ===== Implementation ===== |
rfc/chaining_comparison.1482423776.txt.gz · Last modified: 2017/09/22 13:28 (external edit)