rfc:chaining_comparison
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:chaining_comparison [2016/12/22 16:22] – bp1222 | rfc:chaining_comparison [2016/12/22 17:42] – bp1222 | ||
---|---|---|---|
Line 181: | Line 181: | ||
var_dump(1 < 2 == 3); | var_dump(1 < 2 == 3); | ||
/* | /* | ||
- | * 1 < 2 == 3 := true == 3 := true | + | |
*/ | */ | ||
Line 191: | Line 191: | ||
var_dump(1 < 2 == (3 == 4)); | var_dump(1 < 2 == (3 == 4)); | ||
/* | /* | ||
- | * 1 < 2 == (3 == 4) := true == false := false | + | |
*/ | */ | ||
</ | </ | ||
Line 205: | Line 205: | ||
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 229: | ||
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 255: | Line 273: | ||
Implementation #2: comparisons and equality evaluated together: https:// | Implementation #2: comparisons and equality evaluated together: https:// | ||
+ | |||
+ | (Note: Implementation #2 branched from #1 significantly back in time as a psuedo example. | ||
Will need eyes of those more familiar with AST/VM to review. | Will need eyes of those more familiar with AST/VM to review. |
rfc/chaining_comparison.txt · Last modified: 2021/03/27 14:58 by ilutov