rfc:increment_decrement_fixes
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:increment_decrement_fixes [2020/03/01 18:14] – propose array error; defer object and resource discussion imsop | rfc:increment_decrement_fixes [2020/03/01 21:08] – ready for discussion imsop | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Increment/ | ====== PHP RFC: Increment/ | ||
- | * Version: | + | * Version: |
* Date: 2020-03-01 | * Date: 2020-03-01 | ||
- | * Author: Rowan Tommins, rowan.collins@gmail.com | + | * Author: Rowan Tommins |
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The increment and decrement operators (< | + | The increment and decrement operators (< |
Intuitively, | Intuitively, | ||
Line 25: | Line 25: | ||
Discrepancies in behaviour of null are particularly problematic, | Discrepancies in behaviour of null are particularly problematic, | ||
- | This RFC proposes to change the behaviour, so that < | + | This RFC proposes to change the behaviour, so that < |
^ ^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ^ ^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ||
Line 45: | Line 45: | ||
===== Proposal 3: Error when incrementing or decrementing an array ===== | ===== Proposal 3: Error when incrementing or decrementing an array ===== | ||
- | Adding an integer to an array produces | + | Adding an integer to an array throws |
- | This RFC proposed | + | This RFC proposes |
^ ^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ^ ^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ||
Line 55: | Line 55: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | The proposed changes | + | All of the proposed changes are explicit breaks in compatibility. The justification is that the current behaviour is neither intuitive nor useful. It is unlikely that code is deliberately relying on it, and it is likely that users would expect the behaviour to be consistent with adding 1. |
Line 67: | Line 67: | ||
===== Open Issues ===== | ===== Open Issues ===== | ||
- | None raised yet. | + | None at time of initial discussion. |
===== Unaffected PHP Functionality ===== | ===== Unaffected PHP Functionality ===== | ||
- | * Undefined variables, array items, and object properties are currently treated as null for most purposes, including the < | + | **Undefined variables, array items, and object properties** are currently treated as null for most purposes, including the < |
- | * Similarly, most mathematical contexts will coerce null and false to 0, and true to 1; this RFC does not seek to change any cases where that logic is followed. Changes to that general principle might render this RFC obsolete, but might require a period of deprecation, | + | |
- | * Strings overload the < | + | |
- | * Objects and resources are currently left unchanged by < | + | |
- | For reference, the current behaviour is as follows: | + | Similarly, most mathematical contexts will coerce null and false to 0, and true to 1; this RFC does not seek to change any cases where that logic is followed. Changes to that general principle might render this RFC obsolete, but might require a period of deprecation, |
+ | |||
+ | **Strings** overload the < | ||
+ | |||
+ | **Objects and resources** are also left unchanged with < | ||
+ | |||
+ | For reference, the current behaviour | ||
^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ^ Initial Value ^ %%$a = $a + 1%% ^ %%$a += 1%% ^ %%++$a%%, %%$a++%% ^ %%$a = $a - 1%% ^ %%$a -= 1%% ^ %%--$a%%, %%$a--%% ^ | ||
- | ^ any object | 2 (with Notice) | 2 (with Notice) | no effect | 0 (with Notice) | 0 (with Notice) | no effect | | + | ^ any object | 2 (with E_NOTICE) | 2 (with E_NOTICE) | no effect | 0 (with E_NOTICE) | 0 (with E_NOTICE) | no effect | |
^ resource#1 | 2 | 2 | no effect | 0 | 0 | no effect | | ^ resource#1 | 2 | 2 | no effect | 0 | 0 | no effect | | ||
^ resource#5 | 6 | 6 | no effect | 4 | 4 | no effect | | ^ resource#5 | 6 | 6 | no effect | 4 | 4 | no effect | | ||
Line 87: | Line 90: | ||
===== Proposed Voting Choices ===== | ===== Proposed Voting Choices ===== | ||
- | * Should decrementing null result in -1? (Yes / No) | + | The three proposed changes can be implemented independently, |
- | * Should incrementing and decrementing booleans act the same as addition and subtraction? | + | |
- | * Should incrementing or decrementing an array throw an " | + | |
+ | * Should incrementing and decrementing booleans act the same as addition and subtraction? | ||
+ | * Should incrementing or decrementing an array throw an " | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | The implementation should be a simple addition to the '' | + | None yet. The implementation should be a simple addition to the '' |
===== Implementation ===== | ===== Implementation ===== | ||
Line 102: | Line 107: | ||
===== References ===== | ===== References ===== | ||
- | * [[https:// | + | |
- | * [[https:// | + | * [[https:// |
- | * [[https:// | + | * [[https:// |
===== Rejected Features ===== | ===== Rejected Features ===== | ||
TODO | TODO |
rfc/increment_decrement_fixes.txt · Last modified: 2022/02/18 14:38 by imsop