rfc:increment_decrement_fixes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
rfc:increment_decrement_fixes [2020/03/01 20:25] imsoprfc:increment_decrement_fixes [2020/03/01 21:08] – ready for discussion imsop
Line 1: Line 1:
 ====== PHP RFC: Increment/Decrement Fixes ====== ====== PHP RFC: Increment/Decrement Fixes ======
-  * Version: 0.3+  * Version: 1.0
   * Date: 2020-03-01   * Date: 2020-03-01
-  * Author: Rowan Tommins, rowan.collins@gmail.com +  * Author: Rowan Tommins [IMSoP], rowan.collins@gmail.com 
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/increment_decrement_fixes   * First Published at: http://wiki.php.net/rfc/increment_decrement_fixes
  
Line 25: Line 25:
 Discrepancies in behaviour of null are particularly problematic, since undefined variables, array items, and object properties are currently treated as having a value of null. Discrepancies in behaviour of null are particularly problematic, since undefined variables, array items, and object properties are currently treated as having a value of null.
  
-This RFC proposes to change the behaviour, so that <php>$a=null; $a--;</php> or <php>$a=null; --$a;</php> will result in $a holding -1. This brings it into line with all other mathematical operations, include <php>$a++</php>, which treat null as equivalent to 0.+This RFC proposes to change the behaviour, so that <php>$a=null; $a--;</php> or <php>$a=null; --$a;</php> will result in $a holding -1. This brings it into line with all other mathematical operations, including <php>$a++</php>, which treat null as equivalent to 0.
  
 ^ ^ 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 an "Unsupported operand types" error, but incrementing or decrementing it leaves it unchanged, with no Notice, Warning, or Error.+Adding an integer to an array throws an Error with the message "Unsupported operand types"but incrementing or decrementing an array leaves it unchanged, with no Notice, Warning, or Error.
  
-This RFC proposes to change the behaviour so that <php>$a=[]; $a++;</php> and <php>$a=[]; $a--;</php> raise the same error as <php>$a = [] + 1;</php>.+This RFC proposes to change the behaviour so that <php>$a=[]; $a++;</php> (or <php>++$a</php>and <php>$a=[]; $a--;</php> (or <php>--$a</php>raise the same error as <php>$a = [] + 1;</php>.
  
 ^ ^ 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 =====
  
-All of the proposed changes are explicit breaks in compatibility. The justification is that the current behaviour is neither intuitive nor useful, and it is unlikely that code is deliberately relying on it.+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 89: Line 89:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
 +
 +The three proposed changes can be implemented independently, so three separate votes are proposed, each requiring the standard 2/3 super-majority to be accepted:
  
   * Should decrementing null result in -1? (Yes / No)   * Should decrementing null result in -1? (Yes / No)
Line 105: Line 107:
 ===== References ===== ===== References =====
  
-* [[https://externals.io/message/108602|Pre-RFC discussion]] +  * [[https://externals.io/message/108602|Pre-RFC discussion]] 
-* [[https://wiki.php.net/rfc/alpanumeric_decrement|RFC: Alphanumeric Decrement]] (rejected) +  * [[https://wiki.php.net/rfc/alpanumeric_decrement|RFC: Alphanumeric Decrement]] (rejected) 
-* [[https://wiki.php.net/rfc/normalize_inc_dec|RFC: Normalize inc/dec]] (inactive)+  * [[https://wiki.php.net/rfc/normalize_inc_dec|RFC: Normalize inc/dec]] (inactive)
  
 ===== Rejected Features ===== ===== Rejected Features =====
  
 TODO TODO
rfc/increment_decrement_fixes.txt · Last modified: 2022/02/18 14:38 by imsop